[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.
This commit is contained in:
Martin Gräßlin 2013-10-09 08:26:29 +02:00
parent 1674824e79
commit a98dbd7460
6 changed files with 0 additions and 246 deletions

View file

@ -64,7 +64,6 @@ DecorationModel::DecorationModel(KSharedConfigPtr config, QObject* parent)
{ {
QHash<int, QByteArray> roleNames; QHash<int, QByteArray> roleNames;
roleNames[Qt::DisplayRole] = "display"; roleNames[Qt::DisplayRole] = "display";
roleNames[DecorationModel::PixmapRole] = "preview";
roleNames[TypeRole] = "type"; roleNames[TypeRole] = "type";
roleNames[AuroraeNameRole] = "auroraeThemeName"; roleNames[AuroraeNameRole] = "auroraeThemeName";
roleNames[QmlMainScriptRole] = "mainScript"; roleNames[QmlMainScriptRole] = "mainScript";
@ -225,8 +224,6 @@ QVariant DecorationModel::data(const QModelIndex& index, int role) const
return m_decorations[ index.row()].name; return m_decorations[ index.row()].name;
case LibraryNameRole: case LibraryNameRole:
return m_decorations[ index.row()].libraryName; return m_decorations[ index.row()].libraryName;
case PixmapRole:
return m_decorations[ index.row()].preview;
case TypeRole: case TypeRole:
return m_decorations[ index.row()].type; return m_decorations[ index.row()].type;
case AuroraeNameRole: case AuroraeNameRole:
@ -288,7 +285,6 @@ bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, i
} }
emit dataChanged(index, index); emit dataChanged(index, index);
emit configChanged(m_decorations[ index.row()].auroraeName); emit configChanged(m_decorations[ index.row()].auroraeName);
regeneratePreview(index);
return true; return true;
} }
if (role == ButtonSizeRole && (type == DecorationModelData::AuroraeDecoration || type == DecorationModelData::QmlDecoration)) { 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(); config.sync();
emit dataChanged(index, index); emit dataChanged(index, index);
emit configChanged(m_decorations[ index.row()].auroraeName); emit configChanged(m_decorations[ index.row()].auroraeName);
regeneratePreview(index);
return true; return true;
} }
if (role == CloseOnDblClickRole && (type == DecorationModelData::AuroraeDecoration || type == DecorationModelData::QmlDecoration)) { 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) 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_customButtons = buttons->customPositions();
m_leftButtons = buttons->leftButtons(); m_leftButtons = buttons->leftButtons();
m_rightButtons = buttons->rightButtons(); m_rightButtons = buttons->rightButtons();
if (regenerate)
regeneratePreviews();
} }
void DecorationModel::setButtons(bool custom, const QString& left, const QString& right) 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; m_rightButtons = right;
} }
void DecorationModel::regenerateNextPreview()
{
if (m_nextPreviewIndex < m_lastUpdateIndex && m_nextPreviewIndex < m_decorations.count())
regeneratePreview(index(m_nextPreviewIndex),
QSize(qobject_cast<KWinDecorationModule*>(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 QModelIndex DecorationModel::indexOfLibrary(const QString& libraryName) const
{ {
for (int i = 0; i < m_decorations.count(); i++) { for (int i = 0; i < m_decorations.count(); i++) {

View file

@ -45,7 +45,6 @@ public:
}; };
QString name; QString name;
QString libraryName; QString libraryName;
QPixmap preview;
DecorationType type; DecorationType type;
QString comment; QString comment;
QString author; QString author;
@ -75,7 +74,6 @@ public:
enum { enum {
NameRole = Qt::UserRole, NameRole = Qt::UserRole,
LibraryNameRole = Qt::UserRole + 1, LibraryNameRole = Qt::UserRole + 1,
PixmapRole = Qt::UserRole + 2,
TypeRole = Qt::UserRole + 3, TypeRole = Qt::UserRole + 3,
AuroraeNameRole = Qt::UserRole + 4, AuroraeNameRole = Qt::UserRole + 4,
PackageDescriptionRole = Qt::UserRole + 5, PackageDescriptionRole = Qt::UserRole + 5,
@ -99,8 +97,6 @@ public:
void reload(); void reload();
void regeneratePreview(const QModelIndex& index);
/** /**
* Changes the button state and regenerates the preview. * Changes the button state and regenerates the preview.
*/ */
@ -116,19 +112,12 @@ public:
QModelIndex indexOfName(const QString& decoName) const; QModelIndex indexOfName(const QString& decoName) const;
QModelIndex indexOfAuroraeName(const QString& auroraeName, const QString& type) 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()); Q_INVOKABLE QVariant readConfig(const QString &themeName, const QString &key, const QVariant &defaultValue = QVariant());
void notifyConfigChanged(const QModelIndex &index); void notifyConfigChanged(const QModelIndex &index);
Q_SIGNALS: Q_SIGNALS:
void configChanged(QString themeName); void configChanged(QString themeName);
public Q_SLOTS:
void regeneratePreview(const QModelIndex& index, const QSize& size);
private Q_SLOTS:
void regenerateNextPreview();
private: private:
void findDecorations(); void findDecorations();
void findAuroraeThemes(); void findAuroraeThemes();
@ -140,9 +129,6 @@ private:
QString m_leftButtons; QString m_leftButtons;
QString m_rightButtons; QString m_rightButtons;
KSharedConfigPtr m_config; KSharedConfigPtr m_config;
int m_nextPreviewIndex;
int m_firstUpdateIndex;
int m_lastUpdateIndex;
}; };
} // namespace KWin } // namespace KWin

View file

@ -79,8 +79,6 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList &
, m_proxyModel(NULL) , m_proxyModel(NULL)
, m_configLoaded(false) , m_configLoaded(false)
, m_decorationButtons(new DecorationButtons(this)) , m_decorationButtons(new DecorationButtons(this))
, m_lastPreviewWidth(-1)
, m_previewUpdateTimer(NULL)
, m_listView(new QQuickView()) , m_listView(new QQuickView())
{ {
qmlRegisterType<Aurorae::AuroraeTheme>("org.kde.kwin.aurorae", 0, 1, "AuroraeTheme"); qmlRegisterType<Aurorae::AuroraeTheme>("org.kde.kwin.aurorae", 0, 1, "AuroraeTheme");
@ -153,7 +151,6 @@ void KWinDecorationModule::init()
readConfig(style); readConfig(style);
connect(m_listView->rootObject(), SIGNAL(currentIndexChanged()), SLOT(slotSelectionChanged())); 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->configureButtonsButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureButtons()));
connect(m_ui->ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNSClicked())); connect(m_ui->ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNSClicked()));
connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString)));
@ -174,11 +171,6 @@ void KWinDecorationModule::init()
updateScrollbarRange(); updateScrollbarRange();
} }
int KWinDecorationModule::itemWidth() const
{
return m_listView->rootObject()->property("width").toInt();
}
// This is the selection handler setting // This is the selection handler setting
void KWinDecorationModule::slotSelectionChanged() void KWinDecorationModule::slotSelectionChanged()
{ {
@ -364,8 +356,6 @@ void KWinDecorationModule::slotGHNSClicked()
if (proxyIndex.isValid()) if (proxyIndex.isValid())
m_listView->rootObject()->setProperty("currentIndex", proxyIndex.row()); m_listView->rootObject()->setProperty("currentIndex", proxyIndex.row());
} }
m_lastPreviewWidth = 0;
updatePreviews();
} }
} }
delete downloadDialog; delete downloadDialog;
@ -493,35 +483,6 @@ bool KWinDecorationModule::eventFilter(QObject *o, QEvent *e)
return KCModule::eventFilter(o, 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() void KWinDecorationModule::updateScrollbarRange()
{ {
m_ui->decorationList->verticalScrollBar()->blockSignals(true); m_ui->decorationList->verticalScrollBar()->blockSignals(true);

View file

@ -99,8 +99,6 @@ public:
QString quickHelp() const; QString quickHelp() const;
int itemWidth() const;
Q_SIGNALS: Q_SIGNALS:
void pluginLoad(const KConfigGroup& conf); void pluginLoad(const KConfigGroup& conf);
void pluginSave(KConfigGroup &conf); void pluginSave(KConfigGroup &conf);
@ -122,8 +120,6 @@ private:
void readConfig(const KConfigGroup& conf); void readConfig(const KConfigGroup& conf);
void writeConfig(KConfigGroup &conf); void writeConfig(KConfigGroup &conf);
private Q_SLOTS: private Q_SLOTS:
void updatePreviews();
void updatePreviewWidth();
void updateScrollbarRange(); void updateScrollbarRange();
void updateScrollbarValue(); void updateScrollbarValue();
void updateViewPosition(int v); void updateViewPosition(int v);
@ -138,8 +134,6 @@ private:
bool m_configLoaded; bool m_configLoaded;
DecorationButtons *m_decorationButtons; DecorationButtons *m_decorationButtons;
int m_lastPreviewWidth;
QTimer *m_previewUpdateTimer;
QScopedPointer<QQuickView> m_listView; QScopedPointer<QQuickView> m_listView;
}; };

View file

@ -229,24 +229,6 @@ KDecorationPreview::~KDecorationPreview()
delete options; 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() void KDecorationPreview::disablePreview()
{ {
delete deco[Active]; delete deco[Active];
@ -259,101 +241,18 @@ KDecorationFactory *KDecorationPreview::factory() const
return deco[Active] ? deco[Active]->factory() : 0; 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 QRect KDecorationPreview::windowGeometry(bool active) const
{ {
QWidget *widget = active ? deco[Active]->widget() : deco[Inactive]->widget(); QWidget *widget = active ? deco[Active]->widget() : deco[Inactive]->widget();
return widget->geometry(); 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 QRegion KDecorationPreview::unobscuredRegion(bool active, const QRegion& r) const
{ {
Q_UNUSED(active) Q_UNUSED(active)
return r; return r;
} }
void KDecorationPreview::setMask(const QRegion &region, bool active)
{
if (active) {
m_activeMask = region;
} else {
m_inactiveMask = region;
}
}
KDecorationPreviewBridge::KDecorationPreviewBridge(KDecorationPreview* p, bool a) KDecorationPreviewBridge::KDecorationPreviewBridge(KDecorationPreview* p, bool a)
: preview(p), active(a), m_previewItem(nullptr) : preview(p), active(a), m_previewItem(nullptr)
{ {

View file

@ -85,22 +85,14 @@ public:
explicit KDecorationPreview(QWidget* parent = NULL); explicit KDecorationPreview(QWidget* parent = NULL);
virtual ~KDecorationPreview(); virtual ~KDecorationPreview();
bool recreateDecoration(KDecorationPlugins* plugin);
void disablePreview(); void disablePreview();
KDecorationFactory *factory() const; KDecorationFactory *factory() const;
QRegion unobscuredRegion(bool, const QRegion&) const; QRegion unobscuredRegion(bool, const QRegion&) const;
QRect windowGeometry(bool) 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 &region, bool active);
private: private:
void render(QPainter *painter, KDecoration *decoration, const QSize &recommendedSize, const QPoint &offset, const QRegion &mask) const;
KDecorationPreviewOptions* options; KDecorationPreviewOptions* options;
KDecorationPreviewBridge* bridge[NumWindows]; KDecorationPreviewBridge* bridge[NumWindows];
KDecoration* deco[NumWindows]; KDecoration* deco[NumWindows];
QRegion m_activeMask;
QRegion m_inactiveMask;
}; };
class KDecorationPreviewBridge class KDecorationPreviewBridge