kcm/tabbox: Make the preview show desktop if the option is selected
The thumbnail that represents the "desktop" in the switcher preview is taken from the default wallpaper, and it will update automatically as it changes in future versions of Plasma. The current one is also added along the other thumbnails as a fallback. BUG: 309401 FIXED-IN: 5.24
This commit is contained in:
parent
356fff9920
commit
2797c64eea
7 changed files with 68 additions and 39 deletions
|
@ -38,5 +38,10 @@ install(TARGETS kcm_kwintabbox DESTINATION ${KDE_INSTALL_PLUGINDIR} )
|
|||
|
||||
########### install files ###############
|
||||
install(FILES kwintabbox.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
|
||||
install(FILES thumbnails/konqueror.png thumbnails/kmail.png thumbnails/systemsettings.png thumbnails/dolphin.png DESTINATION ${KDE_INSTALL_DATADIR}/kwin/kcm_kwintabbox)
|
||||
install(FILES thumbnails/konqueror.png
|
||||
thumbnails/kmail.png
|
||||
thumbnails/systemsettings.png
|
||||
thumbnails/dolphin.png
|
||||
thumbnails/desktop.png
|
||||
DESTINATION ${KDE_INSTALL_DATADIR}/kwin/kcm_kwintabbox)
|
||||
install(FILES kwinswitcher.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR})
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
// own
|
||||
#include "layoutpreview.h"
|
||||
#include "thumbnailitem.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QQmlEngine>
|
||||
|
@ -25,7 +25,7 @@ namespace KWin
|
|||
namespace TabBox
|
||||
{
|
||||
|
||||
LayoutPreview::LayoutPreview(const QString &path, QObject *parent)
|
||||
LayoutPreview::LayoutPreview(const QString &path, bool showDesktopThumbnail, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_item(nullptr)
|
||||
{
|
||||
|
@ -52,6 +52,7 @@ LayoutPreview::LayoutPreview(const QString &path, QObject *parent)
|
|||
};
|
||||
if (SwitcherItem *switcher = findSwitcher()) {
|
||||
m_item = switcher;
|
||||
static_cast<ExampleClientModel *>(switcher->model())->showDesktopThumbnail(showDesktopThumbnail);
|
||||
switcher->setVisible(true);
|
||||
}
|
||||
auto findWindow = [item]() -> QQuickWindow* {
|
||||
|
@ -115,50 +116,56 @@ ExampleClientModel::~ExampleClientModel()
|
|||
void ExampleClientModel::init()
|
||||
{
|
||||
if (const auto s = KApplicationTrader::preferredService(QStringLiteral("inode/directory"))) {
|
||||
m_services << s;
|
||||
m_fileManager = s;
|
||||
m_thumbnails << ThumbnailInfo{ WindowThumbnailItem::Dolphin, s->name(), s->icon() };
|
||||
}
|
||||
if (const auto s = KApplicationTrader::preferredService(QStringLiteral("text/html"))) {
|
||||
m_services << s;
|
||||
m_browser = s;
|
||||
m_thumbnails << ThumbnailInfo{ WindowThumbnailItem::Konqueror, s->name(), s->icon() };
|
||||
}
|
||||
if (const auto s = KApplicationTrader::preferredService(QStringLiteral("message/rfc822"))) {
|
||||
m_services << s;
|
||||
m_email = s;
|
||||
m_thumbnails << ThumbnailInfo{ WindowThumbnailItem::KMail, s->name(), s->icon() };
|
||||
}
|
||||
if (const auto s = KService::serviceByDesktopName(QStringLiteral("kdesystemsettings"))) {
|
||||
m_services << s;
|
||||
m_systemSettings = s;
|
||||
m_thumbnails << ThumbnailInfo{ WindowThumbnailItem::Systemsettings, s->name(), s->icon() };
|
||||
}
|
||||
}
|
||||
|
||||
void ExampleClientModel::showDesktopThumbnail(bool showDesktop)
|
||||
{
|
||||
const ThumbnailInfo desktopThumbnail = ThumbnailInfo { WindowThumbnailItem::Desktop, i18n("Show Desktop"), QStringLiteral("desktop") };
|
||||
const int desktopIndex = m_thumbnails.indexOf(desktopThumbnail);
|
||||
if (showDesktop == (desktopIndex >= 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Q_EMIT beginResetModel();
|
||||
if (showDesktop) {
|
||||
m_thumbnails << desktopThumbnail;
|
||||
} else {
|
||||
m_thumbnails.removeAt(desktopIndex);
|
||||
}
|
||||
Q_EMIT endResetModel();
|
||||
}
|
||||
|
||||
QVariant ExampleClientModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
if (!index.isValid() || index.row() >= rowCount()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const ThumbnailInfo &item = m_thumbnails.at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case CaptionRole:
|
||||
return m_services.at(index.row())->name();
|
||||
return item.caption;
|
||||
case MinimizedRole:
|
||||
return false;
|
||||
case DesktopNameRole:
|
||||
return i18nc("An example Desktop Name", "Desktop 1");
|
||||
case IconRole:
|
||||
return m_services.at(index.row())->icon();
|
||||
return item.icon;
|
||||
case WindowIdRole:
|
||||
const auto s = m_services.at(index.row());
|
||||
if (s == m_browser) {
|
||||
return WindowThumbnailItem::Konqueror;
|
||||
} else if (s == m_email) {
|
||||
return WindowThumbnailItem::KMail;
|
||||
} else if (s == m_systemSettings) {
|
||||
return WindowThumbnailItem::Systemsettings;
|
||||
} else if (s == m_fileManager) {
|
||||
return WindowThumbnailItem::Dolphin;
|
||||
}
|
||||
return 0;
|
||||
return item.wId;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -166,10 +173,9 @@ QVariant ExampleClientModel::data(const QModelIndex &index, int role) const
|
|||
QString ExampleClientModel::longestCaption() const
|
||||
{
|
||||
QString caption;
|
||||
for (const auto &item : m_services) {
|
||||
const QString name = item->name();
|
||||
if (name.size() > caption.size()) {
|
||||
caption = name;
|
||||
for (const auto &item : m_thumbnails) {
|
||||
if (item.caption.size() > caption.size()) {
|
||||
caption = item.caption;
|
||||
}
|
||||
}
|
||||
return caption;
|
||||
|
@ -178,7 +184,7 @@ QString ExampleClientModel::longestCaption() const
|
|||
int ExampleClientModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return m_services.size();
|
||||
return m_thumbnails.size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ExampleClientModel::roleNames() const
|
||||
|
|
|
@ -9,11 +9,12 @@
|
|||
#ifndef KWIN_TABBOX_LAYOUTPREVIEW_H
|
||||
#define KWIN_TABBOX_LAYOUTPREVIEW_H
|
||||
|
||||
#include <KService>
|
||||
#include <QAbstractListModel>
|
||||
#include <QQuickView>
|
||||
#include <QRect>
|
||||
|
||||
#include "thumbnailitem.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
|
@ -26,7 +27,7 @@ class LayoutPreview : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LayoutPreview(const QString &path, QObject *parent = nullptr);
|
||||
explicit LayoutPreview(const QString &path, bool showDesktopThumbnail = false, QObject *parent = nullptr);
|
||||
~LayoutPreview() override;
|
||||
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
@ -54,13 +55,21 @@ public:
|
|||
QHash<int, QByteArray> roleNames() const override;
|
||||
Q_INVOKABLE QString longestCaption() const;
|
||||
|
||||
void showDesktopThumbnail(bool showDesktop);
|
||||
|
||||
private:
|
||||
struct ThumbnailInfo {
|
||||
WindowThumbnailItem::Thumbnail wId;
|
||||
QString caption;
|
||||
QString icon;
|
||||
|
||||
bool operator==(const ThumbnailInfo &other) {
|
||||
return wId == other.wId;
|
||||
}
|
||||
};
|
||||
|
||||
void init();
|
||||
QList<KService::Ptr> m_services;
|
||||
KService::Ptr m_fileManager;
|
||||
KService::Ptr m_browser;
|
||||
KService::Ptr m_email;
|
||||
KService::Ptr m_systemSettings;
|
||||
QList<ThumbnailInfo> m_thumbnails;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -377,7 +377,9 @@ void KWinTabBoxConfig::configureEffectClicked()
|
|||
|
||||
if (form->effectComboCurrentData(KWinTabBoxConfigForm::AddonEffect).toBool()) {
|
||||
// Show the preview for addon effect
|
||||
new LayoutPreview(form->effectComboCurrentData(KWinTabBoxConfigForm::LayoutPath).toString(), this);
|
||||
new LayoutPreview(form->effectComboCurrentData(KWinTabBoxConfigForm::LayoutPath).toString(),
|
||||
form->showDesktopMode(),
|
||||
this);
|
||||
} else {
|
||||
// For builtin effect, display a configuration dialog
|
||||
QPointer<QDialog> configDialog = new QDialog(this);
|
||||
|
|
|
@ -141,6 +141,12 @@ void WindowThumbnailItem::findImage()
|
|||
case Dolphin:
|
||||
imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/dolphin.png");
|
||||
break;
|
||||
case Desktop:
|
||||
imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "wallpapers/Next/contents/screenshot.png");
|
||||
if (imagePath.isNull()) {
|
||||
imagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwintabbox/desktop.png");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// ignore
|
||||
break;
|
||||
|
|
|
@ -79,7 +79,8 @@ public:
|
|||
Konqueror = 1,
|
||||
KMail,
|
||||
Systemsettings,
|
||||
Dolphin
|
||||
Dolphin,
|
||||
Desktop,
|
||||
};
|
||||
Q_SIGNALS:
|
||||
void wIdChanged(qulonglong wid);
|
||||
|
|
BIN
src/kcmkwin/kwintabbox/thumbnails/desktop.png
Normal file
BIN
src/kcmkwin/kwintabbox/thumbnails/desktop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 138 KiB |
Loading…
Reference in a new issue