diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index c4b446b773..466d00409c 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -63,7 +63,7 @@ void AuroraeFactory::init() } m_component->loadUrl(QUrl(KStandardDirs::locate("data", "kwin/aurorae/aurorae.qml"))); m_engine->rootContext()->setContextProperty("auroraeTheme", m_theme); - + m_engine->rootContext()->setContextProperty("options", this); } AuroraeFactory::~AuroraeFactory() @@ -82,6 +82,9 @@ AuroraeFactory *AuroraeFactory::instance() bool AuroraeFactory::reset(unsigned long changed) { + if (changed & SettingButtons) { + emit buttonsChanged(); + } init(); resetDecorations(changed); return false; // need hard reset @@ -134,6 +137,21 @@ QDeclarativeItem *AuroraeFactory::createQmlDecoration(Aurorae::AuroraeClient *cl return qobject_cast< QDeclarativeItem* >(m_component->create(context)); } +QString AuroraeFactory::rightButtons() +{ + return options()->titleButtonsRight(); +} + +QString AuroraeFactory::leftButtons() +{ + return options()->titleButtonsLeft(); +} + +bool AuroraeFactory::customButtonPositions() +{ + return options()->customButtonPositions(); +} + AuroraeFactory *AuroraeFactory::s_instance = NULL; /******************************************************* @@ -393,18 +411,6 @@ void AuroraeClient::titleMouseMoved(Qt::MouseButton button, Qt::MouseButtons but event = 0; } -QString AuroraeClient::rightButtons() const -{ - // TODO: make independent of Aurorae - return options()->customButtonPositions() ? options()->titleButtonsRight() : AuroraeFactory::instance()->theme()->defaultButtonsRight(); -} - -QString AuroraeClient::leftButtons() const -{ - // TODO: make independent of Aurorae - return options()->customButtonPositions() ? options()->titleButtonsLeft() : AuroraeFactory::instance()->theme()->defaultButtonsLeft(); -} - void AuroraeClient::themeChanged() { m_scene->clear(); diff --git a/clients/aurorae/src/aurorae.h b/clients/aurorae/src/aurorae.h index 587d285d57..8088aaa37f 100644 --- a/clients/aurorae/src/aurorae.h +++ b/clients/aurorae/src/aurorae.h @@ -37,6 +37,10 @@ class AuroraeClient; class AuroraeFactory : public QObject, public KDecorationFactoryUnstable { + Q_OBJECT + Q_PROPERTY(QString leftButtons READ leftButtons NOTIFY buttonsChanged) + Q_PROPERTY(QString rightButtons READ rightButtons NOTIFY buttonsChanged) + Q_PROPERTY(bool customButtonPositions READ customButtonPositions NOTIFY buttonsChanged) public: ~AuroraeFactory(); @@ -50,11 +54,17 @@ public: return m_theme; } QDeclarativeItem *createQmlDecoration(AuroraeClient *client); + QString leftButtons(); + QString rightButtons(); + bool customButtonPositions(); private: AuroraeFactory(); void init(); +Q_SIGNALS: + void buttonsChanged(); + private: static AuroraeFactory *s_instance; @@ -91,8 +101,6 @@ class AuroraeClient : public KDecorationUnstable Q_PROPERTY(int width READ width) Q_PROPERTY(qulonglong windowId READ windowId CONSTANT) // TODO: window tabs - they suck for dynamic features - Q_PROPERTY(QString leftButtons READ leftButtons CONSTANT) - Q_PROPERTY(QString rightButtons READ rightButtons CONSTANT) public: AuroraeClient(KDecorationBridge* bridge, KDecorationFactory* factory); virtual ~AuroraeClient(); @@ -110,8 +118,6 @@ public: // optional overrides virtual void padding(int &left, int &right, int &top, int &bottom) const; virtual void reset(long unsigned int changed); - QString leftButtons() const; - QString rightButtons() const; bool isMaximized() const; Q_SIGNALS: diff --git a/clients/aurorae/src/lib/auroraetheme.h b/clients/aurorae/src/lib/auroraetheme.h index df7de79b06..3dfd2138aa 100644 --- a/clients/aurorae/src/lib/auroraetheme.h +++ b/clients/aurorae/src/lib/auroraetheme.h @@ -107,6 +107,8 @@ class /*LIBAURORAE_EXPORT*/ AuroraeTheme : public QObject Q_PROPERTY(QColor inactiveTextColor READ inactiveTextColor NOTIFY themeChanged) Q_PROPERTY(Qt::Alignment horizontalAlignment READ alignment NOTIFY themeChanged) Q_PROPERTY(Qt::Alignment verticalAlignment READ verticalAlignment NOTIFY themeChanged) + Q_PROPERTY(QString defaultButtonsLeft READ defaultButtonsLeft NOTIFY themeChanged) + Q_PROPERTY(QString defaultButtonsRight READ defaultButtonsRight NOTIFY themeChanged) public: AuroraeTheme(QObject* parent = 0); virtual ~AuroraeTheme(); diff --git a/clients/aurorae/src/qml/aurorae.qml b/clients/aurorae/src/qml/aurorae.qml index 332e62fe3e..98deb9e4ce 100644 --- a/clients/aurorae/src/qml/aurorae.qml +++ b/clients/aurorae/src/qml/aurorae.qml @@ -96,7 +96,7 @@ Decoration { } AuroraeButtonGroup { id: leftButtonGroup - buttons: decoration.leftButtons + buttons: options.customButtonPositions ? options.leftButtons : auroraeTheme.defaultButtonsLeft width: childrenRect.width anchors { top: parent.top @@ -123,7 +123,7 @@ Decoration { } AuroraeButtonGroup { id: rightButtonGroup - buttons: decoration.rightButtons + buttons: options.customButtonPositions ? options.rightButtons : auroraeTheme.defaultButtonsRight width: childrenRect.width anchors { top: parent.top diff --git a/kcmkwin/kwindecoration/buttonsconfigdialog.cpp b/kcmkwin/kwindecoration/buttonsconfigdialog.cpp index edbffd4aaf..6e46b38a29 100644 --- a/kcmkwin/kwindecoration/buttonsconfigdialog.cpp +++ b/kcmkwin/kwindecoration/buttonsconfigdialog.cpp @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "buttonsconfigdialog.h" +#include "kwindecoration.h" #include @@ -33,12 +34,10 @@ KWinDecorationButtonsConfigForm::KWinDecorationButtonsConfigForm(QWidget* parent setupUi(this); } -KWinDecorationButtonsConfigDialog::KWinDecorationButtonsConfigDialog(bool customPositions, bool showTooltips, QString buttonsLeft, QString buttonsRight, QWidget* parent, Qt::WFlags flags) +KWinDecorationButtonsConfigDialog::KWinDecorationButtonsConfigDialog(DecorationButtons const *buttons, bool showTooltips, QWidget* parent, Qt::WFlags flags) : KDialog(parent, flags) - , m_customPositions(customPositions) , m_showTooltip(showTooltips) - , m_buttonsLeft(buttonsLeft) - , m_buttonsRight(buttonsRight) + , m_buttons(buttons) { m_ui = new KWinDecorationButtonsConfigForm(this); setWindowTitle(i18n("Buttons")); @@ -46,7 +45,7 @@ KWinDecorationButtonsConfigDialog::KWinDecorationButtonsConfigDialog(bool custom enableButton(KDialog::Reset, false); QVBoxLayout* layout = new QVBoxLayout; layout->addWidget(m_ui); - m_ui->buttonPositionWidget->setEnabled(customPositions); + m_ui->buttonPositionWidget->setEnabled(buttons->customPositions()); QWidget* main = new QWidget(this); main->setLayout(layout); @@ -101,10 +100,10 @@ void KWinDecorationButtonsConfigDialog::slotDefaultClicked() void KWinDecorationButtonsConfigDialog::slotResetClicked() { - m_ui->useCustomButtonPositionsCheckBox->setChecked(m_customPositions); + m_ui->useCustomButtonPositionsCheckBox->setChecked(m_buttons->customPositions()); m_ui->showToolTipsCheckBox->setChecked(m_showTooltip); - m_ui->buttonPositionWidget->setButtonsLeft(m_buttonsLeft); - m_ui->buttonPositionWidget->setButtonsRight(m_buttonsRight); + m_ui->buttonPositionWidget->setButtonsLeft(m_buttons->leftButtons()); + m_ui->buttonPositionWidget->setButtonsRight(m_buttons->rightButtons()); changed(); enableButton(KDialog::Reset, false); } diff --git a/kcmkwin/kwindecoration/buttonsconfigdialog.h b/kcmkwin/kwindecoration/buttonsconfigdialog.h index f9a334f2d1..5796e7ef58 100644 --- a/kcmkwin/kwindecoration/buttonsconfigdialog.h +++ b/kcmkwin/kwindecoration/buttonsconfigdialog.h @@ -28,6 +28,8 @@ along with this program. If not, see . namespace KWin { +class DecorationButtons; + class KWinDecorationButtonsConfigForm : public QWidget, public Ui::KWinDecorationButtonsConfigForm { Q_OBJECT @@ -40,7 +42,7 @@ class KWinDecorationButtonsConfigDialog : public KDialog { Q_OBJECT public: - KWinDecorationButtonsConfigDialog(bool customPositions, bool showTooltips, QString buttonsLeft, QString buttonsRight, QWidget* parent = 0, Qt::WFlags flags = 0); + KWinDecorationButtonsConfigDialog(DecorationButtons const *buttons, bool showTooltips, QWidget* parent = 0, Qt::WFlags flags = 0); ~KWinDecorationButtonsConfigDialog(); bool customPositions() const; @@ -55,10 +57,8 @@ private slots: private: KWinDecorationButtonsConfigForm* m_ui; - bool m_customPositions; bool m_showTooltip; - QString m_buttonsLeft; - QString m_buttonsRight; + DecorationButtons const *m_buttons; }; } // namespace KWin diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index 253e896c33..64274d2844 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -236,14 +236,14 @@ bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, i } -void DecorationModel::changeButtons(bool custom, const QString& left, const QString& right) +void DecorationModel::changeButtons(const KWin::DecorationButtons *buttons) { - bool regenerate = (custom != m_customButtons); - if (!regenerate && custom) - regenerate = (left != m_leftButtons) || (right != m_rightButtons); - m_customButtons = custom; - m_leftButtons = left; - m_rightButtons = right; + bool regenerate = (buttons->customPositions() != m_customButtons); + if (!regenerate && buttons->customPositions()) + regenerate = (buttons->leftButtons() != m_leftButtons) || (buttons->rightButtons() != m_rightButtons); + m_customButtons = buttons->customPositions(); + m_leftButtons = buttons->leftButtons(); + m_rightButtons = buttons->rightButtons(); if (regenerate) regeneratePreviews(); } diff --git a/kcmkwin/kwindecoration/decorationmodel.h b/kcmkwin/kwindecoration/decorationmodel.h index 5e1f14f1ff..a932b15ced 100644 --- a/kcmkwin/kwindecoration/decorationmodel.h +++ b/kcmkwin/kwindecoration/decorationmodel.h @@ -33,6 +33,8 @@ class KDecorationPreview; namespace KWin { +class DecorationButtons; + class DecorationModelData { public: @@ -93,7 +95,7 @@ public: /** * Changes the button state and regenerates the preview. */ - void changeButtons(bool custom, const QString& left, const QString& right); + void changeButtons(const DecorationButtons *buttons); /** * Changes the button state without regenerating the preview. */ diff --git a/kcmkwin/kwindecoration/kwindecoration.cpp b/kcmkwin/kwindecoration/kwindecoration.cpp index c18ec293d8..5b2936cd85 100644 --- a/kcmkwin/kwindecoration/kwindecoration.cpp +++ b/kcmkwin/kwindecoration/kwindecoration.cpp @@ -70,10 +70,8 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList & : KCModule(KWinDecoFactory::componentData(), parent) , kwinConfig(KSharedConfig::openConfig("kwinrc")) , m_showTooltips(false) - , m_customPositions(false) - , m_leftButtons(QString()) - , m_rightButtons(QString()) , m_configLoaded(false) + , m_decorationButtons(new DecorationButtons(this)) { qmlRegisterType("org.kde.kwin.aurorae", 0, 1, "AuroraeTheme"); m_ui = new KWinDecorationForm(this); @@ -95,6 +93,7 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList & m_ui->decorationList->engine()->addImportPath(importPath); } m_ui->decorationList->rootContext()->setContextProperty("decorationModel", m_proxyModel); + m_ui->decorationList->rootContext()->setContextProperty("options", m_decorationButtons); m_ui->decorationList->rootContext()->setContextProperty("auroraeSource", KStandardDirs::locate("data", "kwin/aurorae/aurorae.qml")); m_ui->decorationList->setSource(KStandardDirs::locate("data", "kwin/kcm_kwindecoration/main.qml")); @@ -172,16 +171,16 @@ void KWinDecorationModule::readConfig(const KConfigGroup & conf) // Buttons tab // ============ - m_customPositions = conf.readEntry("CustomButtonPositions", false); + m_decorationButtons->setCustomPositions(conf.readEntry("CustomButtonPositions", false)); // Menu and onAllDesktops buttons are default on LHS - m_leftButtons = conf.readEntry("ButtonsOnLeft", KDecorationOptions::defaultTitleButtonsLeft()); + m_decorationButtons->setLeftButtons(conf.readEntry("ButtonsOnLeft", KDecorationOptions::defaultTitleButtonsLeft())); // Help, Minimize, Maximize and Close are default on RHS - m_rightButtons = conf.readEntry("ButtonsOnRight", KDecorationOptions::defaultTitleButtonsRight()); + m_decorationButtons->setRightButtons(conf.readEntry("ButtonsOnRight", KDecorationOptions::defaultTitleButtonsRight())); if (m_configLoaded) - m_model->changeButtons(m_customPositions, m_leftButtons, m_rightButtons); + m_model->changeButtons(m_decorationButtons); else { m_configLoaded = true; - m_model->setButtons(m_customPositions, m_leftButtons, m_rightButtons); + m_model->setButtons(m_decorationButtons->customPositions(), m_decorationButtons->leftButtons(), m_decorationButtons->rightButtons()); } emit KCModule::changed(false); @@ -196,12 +195,12 @@ void KWinDecorationModule::writeConfig(KConfigGroup & conf) // General settings conf.writeEntry("PluginLib", libName); - conf.writeEntry("CustomButtonPositions", m_customPositions); + conf.writeEntry("CustomButtonPositions", m_decorationButtons->customPositions()); conf.writeEntry("ShowToolTips", m_showTooltips); // Button settings - conf.writeEntry("ButtonsOnLeft", m_leftButtons); - conf.writeEntry("ButtonsOnRight", m_rightButtons); + conf.writeEntry("ButtonsOnLeft", m_decorationButtons->leftButtons()); + conf.writeEntry("ButtonsOnRight", m_decorationButtons->rightButtons()); conf.writeEntry("BorderSize", static_cast(m_model->data(index, DecorationModel::BorderSizeRole).toInt())); @@ -243,16 +242,14 @@ void KWinDecorationModule::save() void KWinDecorationModule::defaults() { // Set the KDE defaults - m_customPositions = false; m_showTooltips = true; const QModelIndex index = m_proxyModel->mapFromSource(m_model->indexOfName(i18n("Oxygen"))); if (index.isValid()) m_ui->decorationList->rootObject()->setProperty("currentIndex", index.row()); - m_leftButtons = KDecorationOptions::defaultTitleButtonsLeft(); - m_rightButtons = KDecorationOptions::defaultTitleButtonsRight(); + m_decorationButtons->resetToDefaults(); - m_model->changeButtons(m_customPositions, m_leftButtons, m_rightButtons); + m_model->changeButtons(m_decorationButtons); emit changed(true); } @@ -271,13 +268,13 @@ QString KWinDecorationModule::quickHelp() const void KWinDecorationModule::slotConfigureButtons() { - QPointer< KWinDecorationButtonsConfigDialog > configDialog = new KWinDecorationButtonsConfigDialog(m_customPositions, m_showTooltips, m_leftButtons, m_rightButtons, this); + QPointer< KWinDecorationButtonsConfigDialog > configDialog = new KWinDecorationButtonsConfigDialog(m_decorationButtons, m_showTooltips, this); if (configDialog->exec() == KDialog::Accepted) { - m_customPositions = configDialog->customPositions(); + m_decorationButtons->setCustomPositions(configDialog->customPositions()); m_showTooltips = configDialog->showTooltips(); - m_leftButtons = configDialog->buttonsLeft(); - m_rightButtons = configDialog->buttonsRight(); - m_model->changeButtons(m_customPositions, m_leftButtons, m_rightButtons); + m_decorationButtons->setLeftButtons(configDialog->buttonsLeft()); + m_decorationButtons->setRightButtons(configDialog->buttonsRight()); + m_model->changeButtons(m_decorationButtons); emit changed(true); } @@ -347,6 +344,67 @@ void KWinDecorationModule::slotConfigureDecoration() } } +DecorationButtons::DecorationButtons(QObject *parent) + : QObject(parent) + , m_customPositions(false) + , m_leftButtons(KDecorationOptions::defaultTitleButtonsLeft()) + , m_rightButtons(KDecorationOptions::defaultTitleButtonsRight()) +{ +} + +DecorationButtons::~DecorationButtons() +{ +} + +bool DecorationButtons::customPositions() const +{ + return m_customPositions; +} + +const QString &DecorationButtons::leftButtons() const +{ + return m_leftButtons; +} + +const QString &DecorationButtons::rightButtons() const +{ + return m_rightButtons; +} + +void DecorationButtons::setCustomPositions(bool set) +{ + if (m_customPositions == set) { + return; + } + m_customPositions = set; + emit customPositionsChanged(); +} + +void DecorationButtons::setLeftButtons(const QString &leftButtons) +{ + if (m_leftButtons == leftButtons) { + return; + } + m_leftButtons = leftButtons; + emit leftButtonsChanged(); +} + +void DecorationButtons::setRightButtons (const QString &rightButtons) +{ + if (m_rightButtons == rightButtons) { + return; + } + m_rightButtons = rightButtons; + emit rightButtonsChanged(); +} + +void DecorationButtons::resetToDefaults() +{ + setCustomPositions(false); + setLeftButtons(KDecorationOptions::defaultTitleButtonsLeft()); + setRightButtons(KDecorationOptions::defaultTitleButtonsRight()); +} + } // namespace KWin #include "kwindecoration.moc" diff --git a/kcmkwin/kwindecoration/kwindecoration.h b/kcmkwin/kwindecoration/kwindecoration.h index 30d4b4314a..a78a56a69f 100644 --- a/kcmkwin/kwindecoration/kwindecoration.h +++ b/kcmkwin/kwindecoration/kwindecoration.h @@ -52,6 +52,38 @@ public: explicit KWinDecorationForm(QWidget* parent); }; +class DecorationButtons : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool customButtonPositions READ customPositions WRITE setCustomPositions NOTIFY customPositionsChanged) + Q_PROPERTY(QString leftButtons READ leftButtons WRITE setLeftButtons NOTIFY leftButtonsChanged) + Q_PROPERTY(QString rightButtons READ rightButtons WRITE setRightButtons NOTIFY rightButtonsChanged) +public: + explicit DecorationButtons(QObject *parent = 0); + virtual ~DecorationButtons(); + + bool customPositions() const; + const QString &leftButtons() const; + const QString &rightButtons() const; + + void setCustomPositions(bool set); + void setLeftButtons(const QString &leftButtons); + void setRightButtons(const QString &rightButtons); + +public Q_SLOTS: + void resetToDefaults(); + +Q_SIGNALS: + void customPositionsChanged(); + void leftButtonsChanged(); + void rightButtonsChanged(); + +private: + bool m_customPositions; + QString m_leftButtons; + QString m_rightButtons; +}; + class KWinDecorationModule : public KCModule, public KDecorationDefines { Q_OBJECT @@ -88,13 +120,11 @@ private: KWinDecorationForm* m_ui; bool m_showTooltips; - bool m_customPositions; - QString m_leftButtons; - QString m_rightButtons; DecorationModel* m_model; QSortFilterProxyModel* m_proxyModel; bool m_configLoaded; + DecorationButtons *m_decorationButtons; }; } //namespace