From a98dbd74604a29adef84b4f97ce9845945761a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 9 Oct 2013 08:26:29 +0200 Subject: [PATCH] [kcmdeco] Drop the old preview code All the rendering to QPixmap code in the Model and the Preview is deleted as it's no longer used. The model still has the plugin for the border size functionality. This probably needs a change in the API to make it completely bound to the decoration and not a global thing. --- kcmkwin/kwindecoration/decorationmodel.cpp | 78 ---------------- kcmkwin/kwindecoration/decorationmodel.h | 14 --- kcmkwin/kwindecoration/kwindecoration.cpp | 39 -------- kcmkwin/kwindecoration/kwindecoration.h | 6 -- kcmkwin/kwindecoration/preview.cpp | 101 --------------------- kcmkwin/kwindecoration/preview.h | 8 -- 6 files changed, 246 deletions(-) diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index 1064668cec..f8bce1fbaa 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -64,7 +64,6 @@ DecorationModel::DecorationModel(KSharedConfigPtr config, QObject* parent) { QHash roleNames; roleNames[Qt::DisplayRole] = "display"; - roleNames[DecorationModel::PixmapRole] = "preview"; roleNames[TypeRole] = "type"; roleNames[AuroraeNameRole] = "auroraeThemeName"; roleNames[QmlMainScriptRole] = "mainScript"; @@ -225,8 +224,6 @@ QVariant DecorationModel::data(const QModelIndex& index, int role) const return m_decorations[ index.row()].name; case LibraryNameRole: return m_decorations[ index.row()].libraryName; - case PixmapRole: - return m_decorations[ index.row()].preview; case TypeRole: return m_decorations[ index.row()].type; case AuroraeNameRole: @@ -288,7 +285,6 @@ bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, i } emit dataChanged(index, index); emit configChanged(m_decorations[ index.row()].auroraeName); - regeneratePreview(index); return true; } if (role == ButtonSizeRole && (type == DecorationModelData::AuroraeDecoration || type == DecorationModelData::QmlDecoration)) { @@ -298,7 +294,6 @@ bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, i config.sync(); emit dataChanged(index, index); emit configChanged(m_decorations[ index.row()].auroraeName); - regeneratePreview(index); return true; } if (role == CloseOnDblClickRole && (type == DecorationModelData::AuroraeDecoration || type == DecorationModelData::QmlDecoration)) { @@ -319,14 +314,9 @@ bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, i void DecorationModel::changeButtons(const KWin::DecorationButtons *buttons) { - 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(); } void DecorationModel::setButtons(bool custom, const QString& left, const QString& right) @@ -336,74 +326,6 @@ void DecorationModel::setButtons(bool custom, const QString& left, const QString m_rightButtons = right; } -void DecorationModel::regenerateNextPreview() -{ - if (m_nextPreviewIndex < m_lastUpdateIndex && m_nextPreviewIndex < m_decorations.count()) - regeneratePreview(index(m_nextPreviewIndex), - QSize(qobject_cast(QObject::parent())->itemWidth(), 150)); - ++m_nextPreviewIndex; - if (m_nextPreviewIndex >= m_lastUpdateIndex && m_firstUpdateIndex > 0) { - // do the above ones - m_lastUpdateIndex = qMin(m_firstUpdateIndex, m_decorations.count()); - m_firstUpdateIndex = m_nextPreviewIndex = 0; - } - if (m_nextPreviewIndex < m_lastUpdateIndex) - QMetaObject::invokeMethod(this, "regenerateNextPreview", Qt::QueuedConnection); -} - -void DecorationModel::regeneratePreviews(int firstIndex) -{ - m_firstUpdateIndex = firstIndex; - m_lastUpdateIndex = m_decorations.count(); - m_nextPreviewIndex = firstIndex; - regenerateNextPreview(); -} - -void DecorationModel::stopPreviewGeneration() -{ - m_firstUpdateIndex = m_lastUpdateIndex = m_nextPreviewIndex = 0; -} - -void DecorationModel::regeneratePreview(const QModelIndex& index, const QSize& size) -{ - DecorationModelData& data = m_decorations[ index.row()]; - - switch(data.type) { - case DecorationModelData::NativeDecoration: { - bool enabled = false; - bool loaded; - // m_preview->deco management is not required - // either the deco loads and the following recreateDecoration will sanitize decos (on new factory) - // or the deco does not load and destroyPreviousPlugin() is not called - if ((loaded = m_plugins->loadPlugin(data.libraryName)) && m_preview->recreateDecoration(m_plugins)) { - enabled = true; - } else { - m_preview->disablePreview(); - } - if (loaded) - m_plugins->destroyPreviousPlugin(); - if (enabled) { - m_preview->resize(size); - m_preview->setTempButtons(m_plugins, m_customButtons, m_leftButtons, m_rightButtons); - m_preview->setTempBorderSize(m_plugins, data.borderSize); - data.preview = m_preview->preview(); - } else { - m_decorations.removeAt(index.row()); - } - break; - } - default: - // nothing - break; - } - emit dataChanged(index, index); -} - -void DecorationModel::regeneratePreview(const QModelIndex& index) -{ - regeneratePreview(index, m_decorations.at(index.row()).preview.size()); -} - QModelIndex DecorationModel::indexOfLibrary(const QString& libraryName) const { for (int i = 0; i < m_decorations.count(); i++) { diff --git a/kcmkwin/kwindecoration/decorationmodel.h b/kcmkwin/kwindecoration/decorationmodel.h index 2b5632842f..be70b4603c 100644 --- a/kcmkwin/kwindecoration/decorationmodel.h +++ b/kcmkwin/kwindecoration/decorationmodel.h @@ -45,7 +45,6 @@ public: }; QString name; QString libraryName; - QPixmap preview; DecorationType type; QString comment; QString author; @@ -75,7 +74,6 @@ public: enum { NameRole = Qt::UserRole, LibraryNameRole = Qt::UserRole + 1, - PixmapRole = Qt::UserRole + 2, TypeRole = Qt::UserRole + 3, AuroraeNameRole = Qt::UserRole + 4, PackageDescriptionRole = Qt::UserRole + 5, @@ -99,8 +97,6 @@ public: void reload(); - void regeneratePreview(const QModelIndex& index); - /** * Changes the button state and regenerates the preview. */ @@ -116,19 +112,12 @@ public: QModelIndex indexOfName(const QString& decoName) const; QModelIndex indexOfAuroraeName(const QString& auroraeName, const QString& type) const; - void regeneratePreviews(int firstIndex = 0); - void stopPreviewGeneration(); - Q_INVOKABLE QVariant readConfig(const QString &themeName, const QString &key, const QVariant &defaultValue = QVariant()); void notifyConfigChanged(const QModelIndex &index); Q_SIGNALS: void configChanged(QString themeName); -public Q_SLOTS: - void regeneratePreview(const QModelIndex& index, const QSize& size); -private Q_SLOTS: - void regenerateNextPreview(); private: void findDecorations(); void findAuroraeThemes(); @@ -140,9 +129,6 @@ private: QString m_leftButtons; QString m_rightButtons; KSharedConfigPtr m_config; - int m_nextPreviewIndex; - int m_firstUpdateIndex; - int m_lastUpdateIndex; }; } // namespace KWin diff --git a/kcmkwin/kwindecoration/kwindecoration.cpp b/kcmkwin/kwindecoration/kwindecoration.cpp index f26f740cef..42f07f201f 100644 --- a/kcmkwin/kwindecoration/kwindecoration.cpp +++ b/kcmkwin/kwindecoration/kwindecoration.cpp @@ -79,8 +79,6 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList & , m_proxyModel(NULL) , m_configLoaded(false) , m_decorationButtons(new DecorationButtons(this)) - , m_lastPreviewWidth(-1) - , m_previewUpdateTimer(NULL) , m_listView(new QQuickView()) { qmlRegisterType("org.kde.kwin.aurorae", 0, 1, "AuroraeTheme"); @@ -153,7 +151,6 @@ void KWinDecorationModule::init() readConfig(style); connect(m_listView->rootObject(), SIGNAL(currentIndexChanged()), SLOT(slotSelectionChanged())); - connect(m_listView->rootObject(), SIGNAL(widthChanged()), SLOT(updatePreviewWidth())); connect(m_ui->configureButtonsButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureButtons())); connect(m_ui->ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNSClicked())); connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); @@ -174,11 +171,6 @@ void KWinDecorationModule::init() updateScrollbarRange(); } -int KWinDecorationModule::itemWidth() const -{ - return m_listView->rootObject()->property("width").toInt(); -} - // This is the selection handler setting void KWinDecorationModule::slotSelectionChanged() { @@ -364,8 +356,6 @@ void KWinDecorationModule::slotGHNSClicked() if (proxyIndex.isValid()) m_listView->rootObject()->setProperty("currentIndex", proxyIndex.row()); } - m_lastPreviewWidth = 0; - updatePreviews(); } } delete downloadDialog; @@ -493,35 +483,6 @@ bool KWinDecorationModule::eventFilter(QObject *o, QEvent *e) return KCModule::eventFilter(o, e); } -void KWinDecorationModule::updatePreviews() -{ - if (!m_model) { - return; - } - const int newWidth = m_listView->rootObject()->property("width").toInt(); - if (newWidth == m_lastPreviewWidth) - return; - m_lastPreviewWidth = newWidth; - const int h = m_listView->rootObject()->property("contentHeight").toInt(); - const int y = m_listView->rootObject()->property("contentY").toInt(); - // start at first element in sight - int row = 0; - if (h > 0) - row = qMin(qMax(0, y*m_model->rowCount()/h), m_model->rowCount()); - m_model->regeneratePreviews(row); -} - -void KWinDecorationModule::updatePreviewWidth() -{ - if (!m_previewUpdateTimer) { - m_previewUpdateTimer = new QTimer(this); - m_previewUpdateTimer->setSingleShot(true); - connect(m_previewUpdateTimer, SIGNAL(timeout()), this, SLOT(updatePreviews())); - } - m_model->stopPreviewGeneration(); - m_previewUpdateTimer->start(100); -} - void KWinDecorationModule::updateScrollbarRange() { m_ui->decorationList->verticalScrollBar()->blockSignals(true); diff --git a/kcmkwin/kwindecoration/kwindecoration.h b/kcmkwin/kwindecoration/kwindecoration.h index 286f1acbd7..81419dcabd 100644 --- a/kcmkwin/kwindecoration/kwindecoration.h +++ b/kcmkwin/kwindecoration/kwindecoration.h @@ -99,8 +99,6 @@ public: QString quickHelp() const; - int itemWidth() const; - Q_SIGNALS: void pluginLoad(const KConfigGroup& conf); void pluginSave(KConfigGroup &conf); @@ -122,8 +120,6 @@ private: void readConfig(const KConfigGroup& conf); void writeConfig(KConfigGroup &conf); private Q_SLOTS: - void updatePreviews(); - void updatePreviewWidth(); void updateScrollbarRange(); void updateScrollbarValue(); void updateViewPosition(int v); @@ -138,8 +134,6 @@ private: bool m_configLoaded; DecorationButtons *m_decorationButtons; - int m_lastPreviewWidth; - QTimer *m_previewUpdateTimer; QScopedPointer m_listView; }; diff --git a/kcmkwin/kwindecoration/preview.cpp b/kcmkwin/kwindecoration/preview.cpp index ea4645d9d5..e33ceb5d6b 100644 --- a/kcmkwin/kwindecoration/preview.cpp +++ b/kcmkwin/kwindecoration/preview.cpp @@ -229,24 +229,6 @@ KDecorationPreview::~KDecorationPreview() delete options; } -bool KDecorationPreview::recreateDecoration(KDecorationPlugins* plugins) -{ - for (int i = 0; i < NumWindows; i++) { - delete deco[i]; // deletes also window - deco[i] = plugins->createDecoration(bridge[i]); - deco[i]->init(); - } - - m_activeMask = QRegion(); - m_inactiveMask = QRegion(); - - if (deco[Active] == NULL || deco[Inactive] == NULL) { - return false; - } - - return true; -} - void KDecorationPreview::disablePreview() { delete deco[Active]; @@ -259,101 +241,18 @@ KDecorationFactory *KDecorationPreview::factory() const return deco[Active] ? deco[Active]->factory() : 0; } -QPixmap KDecorationPreview::preview() -{ - QPixmap pixmap(size()); - pixmap.fill(Qt::transparent); - if (!deco[Active] || !deco[Inactive]) - return pixmap; - - int titleBarHeight, leftBorder, rightBorder, xoffset, - dummy1, dummy2, dummy3; - // don't have more than one reference to the same dummy variable in one borders() call. - deco[Active]->borders(dummy1, dummy2, titleBarHeight, dummy3); - deco[Inactive]->borders(leftBorder, rightBorder, dummy1, dummy2); - - titleBarHeight = qMin(int(titleBarHeight * .9), 30); - xoffset = qMin(qMax(10, QApplication::isRightToLeft() - ? leftBorder : rightBorder), 30); - QPainter p; - p.begin(&pixmap); - - const QSize size(width() - xoffset - 20, height() - titleBarHeight - 20); - render(&p, deco[Inactive], size, QPoint(10 + xoffset, 10), m_inactiveMask); - render(&p, deco[Active], size, QPoint(10, 10 + titleBarHeight), m_activeMask); - p.end(); - return pixmap; -} - -void KDecorationPreview::render(QPainter *painter, KDecoration *decoration, const QSize &recommendedSize, const QPoint &offset, const QRegion &mask) const -{ - QWidget *w = decoration->widget(); - QSize size = QSize(recommendedSize) - .expandedTo(decoration->minimumSize()); - int padLeft, padRight, padTop, padBottom; - padLeft = padRight = padTop = padBottom = 0; - bool useMask = true; - decoration->padding(padLeft, padRight, padTop, padBottom); - size.setWidth(size.width() + padLeft + padRight); - size.setHeight(size.height() + padTop + padBottom); - if (padLeft || padRight || padTop || padBottom) { - useMask = false; - } - decoration->resize(size); - - // why an if-else block instead of (useMask ? mask : QRegion())? - // For what reason ever it completely breaks if the mask is copied. - if (useMask) { - w->render(painter, offset + QPoint(-padLeft, - padTop), mask, - QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); - } else { - w->render(painter, offset + QPoint(-padLeft, - padTop), QRegion(), - QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); - } -} - QRect KDecorationPreview::windowGeometry(bool active) const { QWidget *widget = active ? deco[Active]->widget() : deco[Inactive]->widget(); return widget->geometry(); } -void KDecorationPreview::setTempBorderSize(KDecorationPlugins* plugin, KDecorationDefines::BorderSize size) -{ - auto connection = connect(plugin->factory(), &KDecorationFactory::recreateDecorations, [this, plugin] { - // can't handle the change, recreate decorations then - recreateDecoration(plugin); - }); - options->setCustomBorderSize(size); - disconnect(connection); -} - -void KDecorationPreview::setTempButtons(KDecorationPlugins* plugin, bool customEnabled, const QString &left, const QString &right) -{ - auto connection = connect(plugin->factory(), &KDecorationFactory::recreateDecorations, [this, plugin] { - // can't handle the change, recreate decorations then - recreateDecoration(plugin); - }); - options->setCustomTitleButtonsEnabled(customEnabled); - options->setCustomTitleButtons(left, right); - disconnect(connection); -} - QRegion KDecorationPreview::unobscuredRegion(bool active, const QRegion& r) const { Q_UNUSED(active) return r; } -void KDecorationPreview::setMask(const QRegion ®ion, bool active) -{ - if (active) { - m_activeMask = region; - } else { - m_inactiveMask = region; - } -} - KDecorationPreviewBridge::KDecorationPreviewBridge(KDecorationPreview* p, bool a) : preview(p), active(a), m_previewItem(nullptr) { diff --git a/kcmkwin/kwindecoration/preview.h b/kcmkwin/kwindecoration/preview.h index 74e9c4e01f..705f6b6c62 100644 --- a/kcmkwin/kwindecoration/preview.h +++ b/kcmkwin/kwindecoration/preview.h @@ -85,22 +85,14 @@ public: explicit KDecorationPreview(QWidget* parent = NULL); virtual ~KDecorationPreview(); - bool recreateDecoration(KDecorationPlugins* plugin); void disablePreview(); KDecorationFactory *factory() const; QRegion unobscuredRegion(bool, const QRegion&) const; QRect windowGeometry(bool) const; - void setTempBorderSize(KDecorationPlugins* plugin, KDecorationDefines::BorderSize size); - void setTempButtons(KDecorationPlugins* plugin, bool customEnabled, const QString &left, const QString &right); - QPixmap preview(); - void setMask(const QRegion ®ion, bool active); private: - void render(QPainter *painter, KDecoration *decoration, const QSize &recommendedSize, const QPoint &offset, const QRegion &mask) const; KDecorationPreviewOptions* options; KDecorationPreviewBridge* bridge[NumWindows]; KDecoration* deco[NumWindows]; - QRegion m_activeMask; - QRegion m_inactiveMask; }; class KDecorationPreviewBridge