2007-04-29 17:35:43 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
|
2013-10-09 05:26:12 +00:00
|
|
|
* Copyright (c) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KWINDECORATION_PREVIEW_H
|
|
|
|
#define KWINDECORATION_PREVIEW_H
|
|
|
|
|
|
|
|
#include <QWidget>
|
2013-10-09 05:26:12 +00:00
|
|
|
#include <QQuickPaintedItem>
|
2008-01-29 16:44:41 +00:00
|
|
|
#include <kdecoration.h>
|
2008-01-26 19:00:14 +00:00
|
|
|
#include <kdecorationbridge.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kdecoration_plugins_p.h>
|
|
|
|
|
|
|
|
class KDecorationPreviewBridge;
|
|
|
|
class KDecorationPreviewOptions;
|
2013-02-04 16:30:24 +00:00
|
|
|
class QMouseEvent;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-10-09 05:26:12 +00:00
|
|
|
class PreviewItem : public QQuickPaintedItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString library READ libraryName WRITE setLibraryName NOTIFY libraryChanged)
|
|
|
|
public:
|
|
|
|
PreviewItem(QQuickItem *parent = nullptr);
|
|
|
|
virtual ~PreviewItem();
|
|
|
|
virtual void paint(QPainter *painter);
|
|
|
|
|
|
|
|
void setLibraryName(const QString &library);
|
|
|
|
const QString &libraryName() const {
|
|
|
|
return m_libraryName;
|
|
|
|
}
|
|
|
|
void updateDecoration(KDecorationPreviewBridge *bridge);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void libraryChanged();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
|
|
|
virtual void hoverMoveEvent(QHoverEvent *event);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2013-10-09 07:40:26 +00:00
|
|
|
void loadDecorationPlugin();
|
2013-10-09 05:26:12 +00:00
|
|
|
void recreateDecorations();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updatePreview();
|
|
|
|
void updateSize(const QSize &size, KDecoration *decoration, QImage &buffer);
|
|
|
|
void render(QImage *image, KDecoration *decoration);
|
|
|
|
void forwardMoveEvent(QHoverEvent *event, const QRect &geo, KDecoration *deco, QWidget **entered);
|
|
|
|
QScopedPointer<KDecorationPlugins> m_plugins;
|
|
|
|
QScopedPointer<KDecorationPreviewBridge> m_activeBridge;
|
|
|
|
QScopedPointer<KDecorationPreviewBridge> m_inactiveBridge;
|
|
|
|
KDecoration *m_activeDecoration;
|
|
|
|
KDecoration *m_inactiveDecoration;
|
|
|
|
QWidget *m_activeEntered;
|
|
|
|
QWidget *m_inactiveEntered;
|
|
|
|
QString m_libraryName;
|
|
|
|
QImage m_activeBuffer;
|
|
|
|
QImage m_inactiveBuffer;
|
|
|
|
};
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
class KDecorationPreview
|
|
|
|
: public QWidget
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
Q_OBJECT
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
|
|
|
// Note: Windows can't be added or removed without making changes to
|
|
|
|
// the code, since parts of it assume there's just an active
|
|
|
|
// and an inactive window.
|
|
|
|
enum Windows { Inactive = 0, Active, NumWindows };
|
|
|
|
|
2012-12-29 06:34:38 +00:00
|
|
|
explicit KDecorationPreview(QWidget* parent = NULL);
|
2011-01-30 14:34:42 +00:00
|
|
|
virtual ~KDecorationPreview();
|
|
|
|
void disablePreview();
|
2012-07-25 07:58:27 +00:00
|
|
|
KDecorationFactory *factory() const;
|
2011-01-30 14:34:42 +00:00
|
|
|
QRegion unobscuredRegion(bool, const QRegion&) const;
|
|
|
|
QRect windowGeometry(bool) const;
|
|
|
|
private:
|
|
|
|
KDecorationPreviewBridge* bridge[NumWindows];
|
|
|
|
KDecoration* deco[NumWindows];
|
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
class KDecorationPreviewBridge
|
2013-10-01 06:01:10 +00:00
|
|
|
: public KDecorationBridge
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
KDecorationPreviewBridge(KDecorationPreview* preview, bool active);
|
2013-10-09 05:26:12 +00:00
|
|
|
KDecorationPreviewBridge(PreviewItem* preview, bool active);
|
2013-10-01 06:16:00 +00:00
|
|
|
virtual bool isActive() const override;
|
|
|
|
virtual bool isCloseable() const override;
|
|
|
|
virtual bool isMaximizable() const override;
|
|
|
|
virtual MaximizeMode maximizeMode() const override;
|
|
|
|
virtual QuickTileMode quickTileMode() const override;
|
|
|
|
virtual bool isMinimizable() const override;
|
|
|
|
virtual bool providesContextHelp() const override;
|
|
|
|
virtual int desktop() const override;
|
|
|
|
virtual bool isModal() const override;
|
|
|
|
virtual bool isShadeable() const override;
|
|
|
|
virtual bool isShade() const override;
|
|
|
|
virtual bool isSetShade() const override;
|
|
|
|
virtual bool keepAbove() const override;
|
|
|
|
virtual bool keepBelow() const override;
|
|
|
|
virtual bool isMovable() const override;
|
|
|
|
virtual bool isResizable() const override;
|
|
|
|
virtual NET::WindowType windowType(unsigned long supported_types) const override;
|
|
|
|
virtual QIcon icon() const override;
|
|
|
|
virtual QString caption() const override;
|
|
|
|
virtual void processMousePressEvent(QMouseEvent*) override;
|
|
|
|
virtual void showWindowMenu(const QRect &) override;
|
|
|
|
virtual void showWindowMenu(const QPoint &) override;
|
|
|
|
virtual void showApplicationMenu(const QPoint &) override;
|
|
|
|
virtual bool menuAvailable() const override;
|
|
|
|
virtual void performWindowOperation(WindowOperation) override;
|
|
|
|
virtual void setMask(const QRegion&, int) override;
|
|
|
|
virtual bool isPreview() const override;
|
|
|
|
virtual QRect geometry() const override;
|
|
|
|
virtual QRect iconGeometry() const override;
|
|
|
|
virtual QRegion unobscuredRegion(const QRegion& r) const override;
|
|
|
|
virtual WId windowId() const override;
|
|
|
|
virtual void closeWindow() override;
|
|
|
|
virtual void maximize(MaximizeMode mode) override;
|
|
|
|
virtual void minimize() override;
|
|
|
|
virtual void showContextHelp() override;
|
|
|
|
virtual void setDesktop(int desktop) override;
|
|
|
|
virtual void titlebarDblClickOperation() override;
|
|
|
|
virtual void titlebarMouseWheelOperation(int delta) override;
|
|
|
|
virtual void setShade(bool set) override;
|
|
|
|
virtual void setKeepAbove(bool) override;
|
|
|
|
virtual void setKeepBelow(bool) override;
|
|
|
|
virtual int currentDesktop() const override;
|
|
|
|
virtual Qt::WindowFlags initialWFlags() const override;
|
|
|
|
virtual void grabXServer(bool grab) override;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2013-10-01 06:16:00 +00:00
|
|
|
virtual bool compositingActive() const override;
|
|
|
|
virtual QRect transparentRect() const override;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2013-10-07 12:26:03 +00:00
|
|
|
virtual void update(const QRegion ®ion) override;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
// Window tabbing
|
2013-10-01 06:16:00 +00:00
|
|
|
virtual QString caption(int idx) const override;
|
|
|
|
virtual void closeTab(long id) override;
|
|
|
|
virtual void closeTabGroup() override;
|
|
|
|
virtual long currentTabId() const override;
|
|
|
|
virtual QIcon icon(int idx) const override;
|
|
|
|
virtual void setCurrentTab(long id) override;
|
|
|
|
virtual void showWindowMenu(const QPoint &, long id) override;
|
|
|
|
virtual void tab_A_before_B(long A, long B) override;
|
|
|
|
virtual void tab_A_behind_B(long A, long B) override;
|
|
|
|
virtual int tabCount() const override;
|
|
|
|
virtual long tabId(int idx) const override;
|
|
|
|
virtual void untab(long id, const QRect& newGeom) override;
|
|
|
|
virtual WindowOperation buttonToWindowOperation(Qt::MouseButtons button) override;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
KDecorationPreview* preview;
|
2013-10-09 05:26:12 +00:00
|
|
|
PreviewItem *m_previewItem;
|
2011-01-30 14:34:42 +00:00
|
|
|
bool active;
|
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
class KDecorationPreviewOptions
|
|
|
|
: public KDecorationOptions
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
KDecorationPreviewOptions();
|
|
|
|
virtual ~KDecorationPreviewOptions();
|
2013-10-01 06:01:10 +00:00
|
|
|
void updateSettings();
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
void setCustomBorderSize(BorderSize size);
|
|
|
|
void setCustomTitleButtonsEnabled(bool enabled);
|
2013-10-10 11:53:10 +00:00
|
|
|
void setCustomTitleButtons(const QList<DecorationButton> &left, const QList<DecorationButton> &right);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BorderSize customBorderSize;
|
|
|
|
bool customButtonsChanged;
|
|
|
|
bool customButtons;
|
2013-10-10 11:53:10 +00:00
|
|
|
QList<DecorationButton> customTitleButtonsLeft;
|
|
|
|
QList<DecorationButton> customTitleButtonsRight;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
class KDecorationPreviewPlugins
|
|
|
|
: public KDecorationPlugins
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-12-29 06:34:38 +00:00
|
|
|
explicit KDecorationPreviewPlugins(const KSharedConfigPtr &cfg);
|
2011-01-30 14:34:42 +00:00
|
|
|
virtual bool provides(Requirement);
|
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
inline KDecorationPreviewPlugins::KDecorationPreviewPlugins(const KSharedConfigPtr &cfg)
|
2011-01-30 14:34:42 +00:00
|
|
|
: KDecorationPlugins(cfg)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#endif
|