KDE/kdebase/workspace/kcontrol
Ben Cooksley
sourtooth at gmail.com
Sat May 15 02:14:22 CEST 2010
SVN commit 1126843 by bcooksley:
Seperate workspace style from application style, and place them in the appropriate system settings categories.
CCMAIL: plasma-devel at kde.org
A desktopstyle (directory)
A desktopstyle/CMakeLists.txt style/CMakeLists.txt#1126618
A desktopstyle/Messages.sh style/Messages.sh#1126618
A desktopstyle/desktopstyle.desktop style/style.desktop#1126618 [TRAILING SPACE]
A desktopstyle/kcmstyle.cpp style/kcmstyle.cpp#1126618 [License: GPL (v2)]
A desktopstyle/kcmstyle.h style/kcmstyle.h#1126618 [License: GPL (v2)]
A desktopstyle/theme.ui style/theme.ui#1126618
M +2 -2 style/CMakeLists.txt
M +1 -264 style/kcmstyle.cpp
M +2 -16 style/kcmstyle.h
D style/theme.ui
--- trunk/KDE/kdebase/workspace/kcontrol/style/CMakeLists.txt #1126842:1126843
@@ -8,11 +8,11 @@
set(kcm_style_PART_SRCS ../krdb/krdb.cpp styleconfdialog.cpp kcmstyle.cpp)
-kde4_add_ui_files(kcm_style_PART_SRCS stylepreview.ui theme.ui finetuning.ui)
+kde4_add_ui_files(kcm_style_PART_SRCS stylepreview.ui finetuning.ui)
kde4_add_plugin(kcm_style ${kcm_style_PART_SRCS})
-target_link_libraries(kcm_style ${KDE4_KIO_LIBS} ${QIMAGEBLITZ_LIBRARIES} ${X11_LIBRARIES} ${KDE4_PLASMA_LIBS} ${KDE4_KNEWSTUFF3_LIBS})
+target_link_libraries(kcm_style ${KDE4_KIO_LIBS} ${QIMAGEBLITZ_LIBRARIES} ${X11_LIBRARIES})
install(TARGETS kcm_style DESTINATION ${PLUGIN_INSTALL_DIR})
--- trunk/KDE/kdebase/workspace/kcontrol/style/kcmstyle.cpp #1126842:1126843
@@ -44,11 +44,7 @@
#include <KDebug>
#include <KColorScheme>
#include <KStandardDirs>
-#include <knewstuff3/downloaddialog.h>
-#include <Plasma/FrameSvg>
-#include <Plasma/Theme>
-
#include <QtCore/QFile>
#include <QtCore/QSettings>
#include <QtGui/QAbstractItemView>
@@ -121,181 +117,6 @@
}
}
-class ThemeInfo
-{
-public:
- QString package;
- Plasma::FrameSvg *svg;
-};
-
-class ThemeModel : public QAbstractListModel
-{
-public:
- enum { PackageNameRole = Qt::UserRole,
- SvgRole = Qt::UserRole + 1
- };
-
- ThemeModel(QObject *parent = 0);
- virtual ~ThemeModel();
-
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- QModelIndex indexOf(const QString &path) const;
- void reload();
-private:
- QMap<QString, ThemeInfo> m_themes;
-};
-
-ThemeModel::ThemeModel( QObject *parent )
- : QAbstractListModel( parent )
-{
-}
-
-ThemeModel::~ThemeModel()
-{
-}
-
-void ThemeModel::reload()
-{
- reset();
- foreach (const ThemeInfo &info, m_themes) {
- delete info.svg;
- }
- m_themes.clear();
-
- // get all desktop themes
- KPluginInfo::List themeInfos = Plasma::Theme::listThemeInfo();
-
- foreach (const KPluginInfo &themeInfo, themeInfos) {
- kDebug() << themeInfo.name() << themeInfo.pluginName();
- QString name = themeInfo.name();
- if (name.isEmpty()) {
- name = themeInfo.pluginName();
- }
-
- Plasma::Theme *theme = new Plasma::Theme(themeInfo.pluginName(), this);
- Plasma::FrameSvg *svg = new Plasma::FrameSvg(theme);
- svg->setUsingRenderingCache(false);
- svg->setTheme(theme);
- svg->setImagePath("widgets/background");
- svg->setEnabledBorders(Plasma::FrameSvg::AllBorders);
-
- ThemeInfo info;
- info.package = themeInfo.pluginName();
- info.svg = svg;
- m_themes[name] = info;
- }
-
- beginInsertRows(QModelIndex(), 0, m_themes.size());
- endInsertRows();
-}
-
-int ThemeModel::rowCount(const QModelIndex &) const
-{
- return m_themes.size();
-}
-
-QVariant ThemeModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid()) {
- return QVariant();
- }
-
- if (index.row() >= m_themes.size()) {
- return QVariant();
- }
-
- QMap<QString, ThemeInfo>::const_iterator it = m_themes.constBegin();
- for (int i = 0; i < index.row(); ++i) {
- ++it;
- }
-
- switch (role) {
- case Qt::DisplayRole:
- return it.key();
- case PackageNameRole:
- return (*it).package;
- case SvgRole:
- return qVariantFromValue((void*)(*it).svg);
- default:
- return QVariant();
- }
-}
-
-QModelIndex ThemeModel::indexOf(const QString &name) const
-{
- QMapIterator<QString, ThemeInfo> it(m_themes);
- int i = -1;
- while (it.hasNext()) {
- ++i;
- if (it.next().value().package == name) {
- return index(i, 0);
- }
- }
-
- return QModelIndex();
-}
-
-
-class ThemeDelegate : public QAbstractItemDelegate
-{
-public:
- ThemeDelegate(QObject * parent = 0);
-
- virtual void paint(QPainter *painter,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
- virtual QSize sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
-private:
- static const int MARGIN = 5;
-};
-
-ThemeDelegate::ThemeDelegate(QObject* parent)
-: QAbstractItemDelegate(parent)
-{
-}
-
-void ThemeDelegate::paint(QPainter *painter,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) const
-{
- QString title = index.model()->data(index, Qt::DisplayRole).toString();
- QString package = index.model()->data(index, ThemeModel::PackageNameRole).toString();
-
- // highlight selected item
- QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &option, painter);
-
- // draw image
- Plasma::FrameSvg *svg = static_cast<Plasma::FrameSvg *>(
- index.model()->data(index, ThemeModel::SvgRole).value<void *>());
- svg->resizeFrame(QSize(option.rect.width() - (2 * MARGIN), 100 - (2 * MARGIN)));
- QRect imgRect = QRect(option.rect.topLeft(),
- QSize(option.rect.width() - (2 * MARGIN), 100 - (2 * MARGIN)))
- .translated(MARGIN, MARGIN);
- svg->paintFrame(painter, QPoint(option.rect.left() + MARGIN, option.rect.top() + MARGIN));
-
- // draw text
- painter->save();
- QFont font = painter->font();
- font.setWeight(QFont::Bold);
- QString colorFile = KStandardDirs::locate("data", "desktoptheme/" + package + "/colors");
- if (!colorFile.isEmpty()) {
- KSharedConfigPtr colors = KSharedConfig::openConfig(colorFile);
- KColorScheme colorScheme(QPalette::Active, KColorScheme::Window, colors);
- painter->setPen(colorScheme.foreground(KColorScheme::NormalText).color());
- }
- painter->setFont(font);
- painter->drawText(option.rect, Qt::AlignCenter | Qt::TextWordWrap, title);
- painter->restore();
-}
-
-
-QSize ThemeDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const
-{
- return QSize(200, 100);
-}
-
class StylePreview : public QWidget, public Ui::StylePreview
{
public:
@@ -345,14 +166,9 @@
"of user interface elements, such as the widget style "
"and effects."));
- m_bDesktopThemeDirty = false;
m_bStyleDirty= false;
m_bEffectsDirty = false;
-
- KAutostart plasmaNetbookAutoStart("plasma-netbook");
- m_isNetbook = plasmaNetbookAutoStart.autostarts();
-
KGlobal::dirs()->addResourceType("themes", "data", "kstyle/themes");
KAboutData *about =
@@ -373,23 +189,6 @@
tabWidget = new QTabWidget( this );
mainLayout->addWidget( tabWidget );
- // Add Page0 (Desktop Theme)
- // -------------------
- page0 = new QWidget;
- themeUi.setupUi(page0);
-
- themeUi.m_newThemeButton->setIcon(KIcon("get-hot-new-stuff"));
-
- m_themeModel = new ThemeModel(this);
- themeUi.m_theme->setModel(m_themeModel);
- themeUi.m_theme->setItemDelegate(new ThemeDelegate(themeUi.m_theme));
- themeUi.m_theme->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
-
- connect(themeUi.m_theme->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(setDesktopThemeDirty()));
- connect(themeUi.m_newThemeButton, SIGNAL(clicked()), this, SLOT(getNewThemes()));
-
- m_workspaceThemeTabActivated = false;
-
// Add Page1 (Applications Style)
// -----------------
//gbWidgetStyle = new QGroupBox( i18n("Widget Style"), page1 );
@@ -462,7 +261,6 @@
// Insert the pages into the tabWidget
tabWidget->addTab(page1, i18nc("@title:tab", "&Applications"));
- tabWidget->addTab(page0, i18nc("@title:tab", "&Workspace"));
tabWidget->addTab(page2, i18nc("@title:tab", "&Fine Tuning"));
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
@@ -560,13 +358,9 @@
{
KConfig config( "kdeglobals", KConfig::FullConfig );
- if (m_workspaceThemeTabActivated) {
- loadDesktopTheme();
- }
loadStyle( config );
loadEffects( config );
- m_bDesktopThemeDirty = false;
m_bStyleDirty= false;
m_bEffectsDirty = false;
//Enable/disable the button for the initial style
@@ -579,21 +373,9 @@
void KCMStyle::save()
{
// Don't do anything if we don't need to.
- if ( !( m_bDesktopThemeDirty | m_bStyleDirty | m_bEffectsDirty ) )
+ if ( !( m_bStyleDirty | m_bEffectsDirty ) )
return;
- //Desktop theme
- if ( m_bDesktopThemeDirty )
- {
- QString theme = m_themeModel->data(themeUi.m_theme->currentIndex(), ThemeModel::PackageNameRole).toString();
- if (m_isNetbook) {
- KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-netbook");
- cg.writeEntry("name", theme);
- } else {
- Plasma::Theme::defaultTheme()->setThemeName(theme);
- }
- }
-
// Save effects.
KConfig _config("kdeglobals", KConfig::NoGlobals);
KConfigGroup config(&_config, "KDE");
@@ -645,7 +427,6 @@
}
// Clean up
- m_bDesktopThemeDirty = false;
m_bStyleDirty = false;
m_bEffectsDirty = false;
emit changed( false );
@@ -703,12 +484,6 @@
emit changed(true);
}
-void KCMStyle::setDesktopThemeDirty()
-{
- m_bDesktopThemeDirty = true;
- emit changed(true);
-}
-
void KCMStyle::setEffectsDirty()
{
m_bEffectsDirty = true;
@@ -721,45 +496,7 @@
emit changed(true);
}
-void KCMStyle::tabChanged(int index)
-{
- if (index == 1 && !m_workspaceThemeTabActivated) { //Workspace theme tab (never loaded before)
- m_workspaceThemeTabActivated = true;
- QTimer::singleShot(100, this, SLOT(loadDesktopTheme()));
- }
-}
-
// ----------------------------------------------------------------
-// All the Desktop Theme stuff
-// ----------------------------------------------------------------
-
-void KCMStyle::getNewThemes()
-{
- KNS3::DownloadDialog dialog("plasma-themes.knsrc", this);
- dialog.exec();
- KNS3::Entry::List entries = dialog.changedEntries();
-
- if (entries.size() > 0) {
- loadDesktopTheme();
- }
-}
-
-void KCMStyle::loadDesktopTheme()
-{
- QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
- m_themeModel->reload();
- QString themeName;
- if (m_isNetbook) {
- KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-netbook");
- themeName = cg.readEntry("name", "air-netbook");
- } else {
- themeName = Plasma::Theme::defaultTheme()->themeName();
- }
- themeUi.m_theme->setCurrentIndex(m_themeModel->indexOf(themeName));
- QApplication::restoreOverrideCursor();
-}
-
-// ----------------------------------------------------------------
// All the Style Switching / Preview stuff
// ----------------------------------------------------------------
--- trunk/KDE/kdebase/workspace/kcontrol/style/kcmstyle.h #1126842:1126843
@@ -47,8 +47,6 @@
class StylePreview;
class QTabWidget;
-class ThemeModel;
-
struct StyleEntry {
QString name;
QString desc;
@@ -80,40 +78,28 @@
virtual void changeEvent( QEvent *event );
protected Q_SLOTS:
- void loadDesktopTheme();
-
void styleSpecificConfig();
void updateConfigButton();
- void setDesktopThemeDirty();
void setStyleDirty();
void setEffectsDirty();
void styleChanged();
- void getNewThemes();
-
- void tabChanged(int);
-
private:
QString currentStyle();
static QString toolbarButtonText(int index);
static int toolbarButtonIndex(const QString &text);
- bool m_bDesktopThemeDirty, m_bStyleDirty, m_bEffectsDirty;
+ bool m_bStyleDirty, m_bEffectsDirty;
QHash <QString,StyleEntry*> styleEntries;
QMap <QString,QString> nameToStyleKey;
QVBoxLayout* mainLayout;
QTabWidget* tabWidget;
- QWidget *page0, *page1, *page2;
+ QWidget *page1, *page2;
QVBoxLayout* page1Layout;
- //Page0
- Ui::theme themeUi;
- ThemeModel* m_themeModel;
-
-
// Page1 widgets
QVBoxLayout* gbWidgetStyleLayout;
QHBoxLayout* hbLayout;
More information about the Plasma-devel
mailing list