[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/systemsettings/icons
From: Ben Cooksley <sourtooth () gmail ! com>
Date: 2009-07-29 6:34:04
Message-ID: 1248849244.627540.14073.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1004025 by bcooksley:
Move classes to their own independent files, as per System Settings coding style
M +2 -0 CMakeLists.txt
A CategorizedView.cpp IconMode.h#1003883 [License: GPL (v2+)]
A CategorizedView.h IconMode.h#1003883 [License: GPL (v2+)]
A CategoryDrawer.cpp [License: GPL (v2+)]
A CategoryDrawer.h IconMode.h#1003883 [License: GPL (v2+)]
M +5 -209 IconMode.cpp
M +0 -2 IconMode.h
--- trunk/KDE/kdebase/workspace/systemsettings/icons/CMakeLists.txt #1004024:1004025
@@ -1,5 +1,7 @@
SET( icon_mode_srcs
IconMode.cpp
+ CategoryDrawer.cpp
+ CategorizedView.cpp
)
KDE4_ADD_PLUGIN(icon_mode ${icon_mode_srcs})
--- trunk/KDE/kdebase/workspace/systemsettings/icons/IconMode.cpp #1004024:1004025
@@ -18,14 +18,14 @@
***************************************************************************/
#include "IconMode.h"
+#include "CategoryDrawer.h"
+#include "CategorizedView.h"
#include "MenuItem.h"
#include "MenuModel.h"
#include "ModuleView.h"
#include "MenuProxyModel.h"
-#include <QPainter>
-#include <QApplication>
#include <QStackedWidget>
#include <KAction>
@@ -33,8 +33,6 @@
#include <KTabWidget>
#include <KAboutData>
#include <KStandardAction>
-#include <KCategoryDrawer>
-#include <KCategorizedView>
#include <KFileItemDelegate>
K_PLUGIN_FACTORY( IconModeFactory, registerPlugin<IconMode>(); )
@@ -42,7 +40,7 @@
class IconMode::Private {
public:
- Private() : moduleView( 0 ) {}
+ Private() : moduleView( 0 ) {}
virtual ~Private() {
qDeleteAll( mCategoryDrawers );
delete aboutIcon;
@@ -59,211 +57,9 @@
KAction * backAction;
};
-class IconMode::CategoryDrawer
- : public KCategoryDrawerV2
-{
-public:
- CategoryDrawer();
-
- virtual void drawCategory(const QModelIndex &index,
- int sortRole,
- const QStyleOption &option,
- QPainter *painter) const;
-
- virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) \
const;
-};
-
-IconMode::CategoryDrawer::CategoryDrawer()
-{
- setLeftMargin( 7 );
- setRightMargin( 7 );
-}
-
-void IconMode::CategoryDrawer::drawCategory(const QModelIndex &index,
- int sortRole,
- const QStyleOption &option,
- QPainter *painter) const
-{
- painter->setRenderHint(QPainter::Antialiasing);
-
- const QRect optRect = option.rect;
- QFont font(QApplication::font());
- font.setBold(true);
- const QFontMetrics fontMetrics = QFontMetrics(font);
- const int height = categoryHeight(index, option);
-
- //BEGIN: decoration gradient
- {
- QPainterPath path(optRect.bottomLeft());
- path.lineTo(QPoint(optRect.topLeft().x(), optRect.topLeft().y() - 3));
- const QPointF topLeft(optRect.topLeft());
- QRectF arc(topLeft, QSizeF(4, 4));
- path.arcTo(arc, 180, -90);
- path.lineTo(optRect.topRight());
- path.lineTo(optRect.bottomRight());
- path.lineTo(optRect.bottomLeft());
-
- QColor window(option.palette.window().color());
- const QColor base(option.palette.base().color());
-
- window.setAlphaF(0.4);
-
- QLinearGradient decoGradient1(optRect.topLeft(), optRect.bottomLeft());
- decoGradient1.setColorAt(0, window);
- decoGradient1.setColorAt(1, Qt::transparent);
-
- QLinearGradient decoGradient2(optRect.topLeft(), optRect.topRight());
- decoGradient2.setColorAt(0, Qt::transparent);
- decoGradient2.setColorAt(1, base);
-
- painter->fillPath(path, decoGradient1);
- painter->fillPath(path, decoGradient2);
- }
- //END: decoration gradient
-
- {
- QRect newOptRect(optRect);
- newOptRect.setLeft(newOptRect.left() + 1);
- newOptRect.setTop(newOptRect.top() + 1);
-
- //BEGIN: inner top left corner
- {
- painter->save();
- painter->setPen(option.palette.base().color());
- const QPointF topLeft(newOptRect.topLeft());
- QRectF arc(topLeft, QSizeF(4, 4));
- arc.translate(0.5, 0.5);
- painter->drawArc(arc, 1440, 1440);
- painter->restore();
- }
- //END: inner top left corner
-
- //BEGIN: inner left vertical line
- {
- QPoint start(newOptRect.topLeft());
- start.ry() += 3;
- QPoint verticalGradBottom(newOptRect.topLeft());
- verticalGradBottom.ry() += newOptRect.height() - 3;
- QLinearGradient gradient(start, verticalGradBottom);
- gradient.setColorAt(0, option.palette.base().color());
- gradient.setColorAt(1, Qt::transparent);
- painter->fillRect(QRect(start, QSize(1, newOptRect.height() - 3)), \
gradient);
- }
- //END: inner left vertical line
-
- //BEGIN: inner horizontal line
- {
- QPoint start(newOptRect.topLeft());
- start.rx() += 3;
- QPoint horizontalGradTop(newOptRect.topLeft());
- horizontalGradTop.rx() += newOptRect.width() - 3;
- QLinearGradient gradient(start, horizontalGradTop);
- gradient.setColorAt(0, option.palette.base().color());
- gradient.setColorAt(1, Qt::transparent);
- painter->fillRect(QRect(start, QSize(newOptRect.width() - 3, 1)), \
gradient);
- }
- //END: inner horizontal line
- }
-
- QColor outlineColor = option.palette.text().color();
- outlineColor.setAlphaF(0.35);
-
- //BEGIN: top left corner
- {
- painter->save();
- painter->setPen(outlineColor);
- const QPointF topLeft(optRect.topLeft());
- QRectF arc(topLeft, QSizeF(4, 4));
- arc.translate(0.5, 0.5);
- painter->drawArc(arc, 1440, 1440);
- painter->restore();
- }
- //END: top left corner
-
- //BEGIN: left vertical line
- {
- QPoint start(optRect.topLeft());
- start.ry() += 3;
- QPoint verticalGradBottom(optRect.topLeft());
- verticalGradBottom.ry() += optRect.height() - 3;
- QLinearGradient gradient(start, verticalGradBottom);
- gradient.setColorAt(0, outlineColor);
- gradient.setColorAt(1, option.palette.base().color());
- painter->fillRect(QRect(start, QSize(1, optRect.height() - 3)), gradient);
- }
- //END: left vertical line
-
- //BEGIN: horizontal line
- {
- QPoint start(optRect.topLeft());
- start.rx() += 3;
- QPoint horizontalGradTop(optRect.topLeft());
- horizontalGradTop.rx() += optRect.width() - 3;
- QLinearGradient gradient(start, horizontalGradTop);
- gradient.setColorAt(0, outlineColor);
- gradient.setColorAt(1, option.palette.base().color());
- painter->fillRect(QRect(start, QSize(optRect.width() - 3, 1)), gradient);
- }
- //END: horizontal line
-
- //BEGIN: draw text
- {
- const QString category = index.model()->data(index, \
KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
- QRect textRect = QRect(option.rect.topLeft(), QSize(option.rect.width(), \
height));
- textRect.setTop(textRect.top() + 2 + 3 /* corner */);
- textRect.setLeft(textRect.left() + 2 + 3 /* corner */ + 3 /* a bit of margin \
*/);
- painter->save();
- painter->setFont(font);
- QColor penColor(option.palette.text().color());
- penColor.setAlphaF(0.6);
- painter->setPen(penColor);
- painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, category);
- painter->restore();
- }
- //END: draw text
-}
-
-int IconMode::CategoryDrawer::categoryHeight(const QModelIndex &index, const \
QStyleOption &option) const
-{
- QFont font(QApplication::font());
- font.setBold(true);
- const QFontMetrics fontMetrics = QFontMetrics(font);
-
- return fontMetrics.height() + 2 + 12 /* vertical spacing */;
-}
-
-class IconMode::CategorizedView
- : public KCategorizedView
-{
-public:
- CategorizedView( QWidget *parent = 0 );
-
- virtual void setModel( QAbstractItemModel *model );
-};
-
-IconMode::CategorizedView::CategorizedView( QWidget *parent )
- : KCategorizedView( parent )
-{
- setWordWrap( true );
-}
-
-void IconMode::CategorizedView::setModel( QAbstractItemModel *model )
-{
- KCategorizedView::setModel( model );
- int maxWidth = -1;
- int maxHeight = -1;
- for ( int i = 0; i < model->rowCount(); ++i ) {
- const QModelIndex index = model->index(i, modelColumn(), rootIndex());
- const QSize size = sizeHintForIndex( index );
- maxWidth = qMax( maxWidth, size.width() );
- maxHeight = qMax( maxHeight, size.height() );
- }
- setGridSize( QSize( maxWidth, maxHeight ) );
- static_cast<KFileItemDelegate*>( itemDelegate() )->setMaximumSize( QSize( \
maxWidth, maxHeight ) );
-}
-
IconMode::IconMode( QObject *parent, const QVariantList& )
- : BaseMode( parent ), d( new Private() )
+ : BaseMode( parent )
+ , d( new Private() )
{
d->aboutIcon = new KAboutData( "IconView", 0, ki18n( "Icon View" ),
"1.0", ki18n( "Provides a categorized icons view of \
control modules." ),
--- trunk/KDE/kdebase/workspace/systemsettings/icons/IconMode.h #1004024:1004025
@@ -55,8 +55,6 @@
private:
class Private;
- class CategoryDrawer;
- class CategorizedView;
Private *const d;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic