2010-10-12 19:51:57 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright 2010 Marco Martin <mart@kde.org> *
|
2014-03-05 12:14:40 +01:00
|
|
|
* Copyright 2014 David Edmundson <davidedmundson@kde.org> *
|
|
|
|
* *
|
2010-10-12 19:51:57 +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 FRAMESVGITEM_P
|
|
|
|
#define FRAMESVGITEM_P
|
|
|
|
|
2014-03-05 12:14:40 +01:00
|
|
|
#include <QQuickItem>
|
don't regenerate frames when setting every property
Summary:
give frameSvg the concept of repaintBlocked(), that enables and
disables the regeneration of the frame data when a property is set.
the use case is when often, a lot of properties are set one after
the other (such as prefix, enabled borders, size)
collapse the formely similar, but a bit different logic of frame
regeneration is a single function for better maintanability.
QML FrameSvgItem sets repaintblocked when it starts and releases it just on oncomponentCompleted
Test Plan:
plasmashell still starts, autotests still work, all frames are rendered correctly
the destruction of old frames is cutted by 50%. in the qml profiler
the creation time of a framesvgitem slightly improved, on this machine from around 26 msecs to around 21, can still be improved, but at least the code is a bit simpler
Reviewers: #plasma
Subscribers: davidedmundson, plasma-devel, #frameworks
Tags: #plasma, #frameworks
Differential Revision: https://phabricator.kde.org/D4414
2017-02-07 13:05:57 +01:00
|
|
|
#include <QQmlParserStatus>
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2010-11-05 20:50:28 +00:00
|
|
|
#include <Plasma/FrameSvg>
|
|
|
|
|
2014-01-28 15:15:55 +01:00
|
|
|
#include "units.h"
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
class FrameSvg;
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2014-08-12 21:03:30 +02:00
|
|
|
/**
|
|
|
|
* @class FrameSvgItemMargins
|
|
|
|
*
|
2014-10-13 15:14:56 +02:00
|
|
|
* @short The sizes of a frame's margins.
|
2014-08-12 21:03:30 +02:00
|
|
|
*/
|
2010-10-12 19:51:57 +00:00
|
|
|
class FrameSvgItemMargins : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2012-01-10 12:29:35 +01:00
|
|
|
/**
|
2014-10-13 15:14:56 +02:00
|
|
|
* Width in pixels of the left margin.
|
2012-01-10 12:29:35 +01:00
|
|
|
*/
|
2010-10-12 19:51:57 +00:00
|
|
|
Q_PROPERTY(qreal left READ left NOTIFY marginsChanged)
|
2012-01-10 12:29:35 +01:00
|
|
|
|
|
|
|
/**
|
2014-10-13 15:14:56 +02:00
|
|
|
* Height in pixels of the top margin.
|
2012-01-10 12:29:35 +01:00
|
|
|
*/
|
2010-10-12 19:51:57 +00:00
|
|
|
Q_PROPERTY(qreal top READ top NOTIFY marginsChanged)
|
2012-01-10 12:29:35 +01:00
|
|
|
|
|
|
|
/**
|
2014-10-13 15:14:56 +02:00
|
|
|
* Width in pixels of the right margin.
|
2012-01-10 12:29:35 +01:00
|
|
|
*/
|
2010-10-12 19:51:57 +00:00
|
|
|
Q_PROPERTY(qreal right READ right NOTIFY marginsChanged)
|
2012-01-10 12:29:35 +01:00
|
|
|
|
|
|
|
/**
|
2014-10-13 15:14:56 +02:00
|
|
|
* Height in pixels of the bottom margin.
|
2012-01-10 12:29:35 +01:00
|
|
|
*/
|
2010-10-12 19:51:57 +00:00
|
|
|
Q_PROPERTY(qreal bottom READ bottom NOTIFY marginsChanged)
|
|
|
|
|
2014-10-13 15:14:56 +02:00
|
|
|
/**
|
|
|
|
* Width in pixels of the left and right margins combined.
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(qreal horizontal READ horizontal NOTIFY marginsChanged)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Height in pixels of the top and bottom margins combined.
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(qreal vertical READ vertical NOTIFY marginsChanged)
|
|
|
|
|
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
public:
|
2017-12-13 07:35:58 +01:00
|
|
|
FrameSvgItemMargins(Plasma::FrameSvg *frameSvg, QObject *parent = nullptr);
|
2010-10-12 19:51:57 +00:00
|
|
|
|
|
|
|
qreal left() const;
|
|
|
|
qreal top() const;
|
|
|
|
qreal right() const;
|
|
|
|
qreal bottom() const;
|
2014-10-13 15:14:56 +02:00
|
|
|
qreal horizontal() const;
|
|
|
|
qreal vertical() const;
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2017-11-14 03:13:07 +01:00
|
|
|
/// returns a vector with left, top, right, bottom
|
|
|
|
QVector<qreal> margins() const;
|
|
|
|
|
2014-02-21 21:13:12 +01:00
|
|
|
void setFixed(bool fixed);
|
|
|
|
bool isFixed() const;
|
|
|
|
|
2012-11-07 12:43:11 +01:00
|
|
|
public Q_SLOTS:
|
|
|
|
void update();
|
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void marginsChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
FrameSvg *m_frameSvg;
|
2014-02-21 21:13:12 +01:00
|
|
|
bool m_fixed;
|
2010-10-12 19:51:57 +00:00
|
|
|
};
|
|
|
|
|
2014-08-12 21:03:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class FrameSvgItem
|
|
|
|
*
|
|
|
|
* @short Provides an SVG with borders.
|
|
|
|
*
|
|
|
|
* It is exposed as org.kde.plasma.core.FrameSvgItem
|
|
|
|
*/
|
2014-03-05 12:14:40 +01:00
|
|
|
class FrameSvgItem : public QQuickItem
|
2010-10-12 19:51:57 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
don't regenerate frames when setting every property
Summary:
give frameSvg the concept of repaintBlocked(), that enables and
disables the regeneration of the frame data when a property is set.
the use case is when often, a lot of properties are set one after
the other (such as prefix, enabled borders, size)
collapse the formely similar, but a bit different logic of frame
regeneration is a single function for better maintanability.
QML FrameSvgItem sets repaintblocked when it starts and releases it just on oncomponentCompleted
Test Plan:
plasmashell still starts, autotests still work, all frames are rendered correctly
the destruction of old frames is cutted by 50%. in the qml profiler
the creation time of a framesvgitem slightly improved, on this machine from around 26 msecs to around 21, can still be improved, but at least the code is a bit simpler
Reviewers: #plasma
Subscribers: davidedmundson, plasma-devel, #frameworks
Tags: #plasma, #frameworks
Differential Revision: https://phabricator.kde.org/D4414
2017-02-07 13:05:57 +01:00
|
|
|
Q_INTERFACES(QQmlParserStatus)
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2012-01-10 12:29:35 +01:00
|
|
|
/**
|
|
|
|
* Theme relative path of the svg, like "widgets/background"
|
|
|
|
*/
|
2012-08-11 19:13:21 -03:00
|
|
|
Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged)
|
2012-01-10 12:29:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* prefix for the 9 piece svg, like "pushed" or "normal" for the button
|
|
|
|
* see http://techbase.kde.org/Development/Tutorials/Plasma/ThemeDetails
|
|
|
|
* for a list of paths and prefixes
|
possibility to use a fallback chain as prefix
Summary:
if a framesvgitem has an array as prefix, like
FrameSvg {
prefix: ["toolbutton-hover", "hover"]
}
it will use the first available prefix, so on themes that
have toolbutton-hover, that one will be used, old themes will
continue to use "hover" as prefix
Test Plan:
tested the calendar with breeze theme has breeze-widget style
toolbuttons, with olt themes as air, the old behavior is still
there, switching on the fly works
Reviewers: davidedmundson, #plasma
Subscribers: davidedmundson, broulik, plasma-devel, #frameworks
Tags: #plasma, #frameworks
Differential Revision: https://phabricator.kde.org/D4827
2017-02-27 18:54:22 +01:00
|
|
|
* It can also be an array of strings, specifying a fallback chain in case
|
|
|
|
* the first element isn't found in the theme, eg ["toolbutton-normal", "normal"]
|
|
|
|
* so it's easy to keep backwards compatibility with old themes
|
|
|
|
* (Note: fallback chain is supported only @since 5.32)
|
2012-01-10 12:29:35 +01:00
|
|
|
*/
|
possibility to use a fallback chain as prefix
Summary:
if a framesvgitem has an array as prefix, like
FrameSvg {
prefix: ["toolbutton-hover", "hover"]
}
it will use the first available prefix, so on themes that
have toolbutton-hover, that one will be used, old themes will
continue to use "hover" as prefix
Test Plan:
tested the calendar with breeze theme has breeze-widget style
toolbuttons, with olt themes as air, the old behavior is still
there, switching on the fly works
Reviewers: davidedmundson, #plasma
Subscribers: davidedmundson, broulik, plasma-devel, #frameworks
Tags: #plasma, #frameworks
Differential Revision: https://phabricator.kde.org/D4827
2017-02-27 18:54:22 +01:00
|
|
|
Q_PROPERTY(QVariant prefix READ prefix WRITE setPrefix NOTIFY prefixChanged)
|
2012-01-10 12:29:35 +01:00
|
|
|
|
2017-06-07 18:22:34 +02:00
|
|
|
/**
|
|
|
|
* the actual prefix that was used, if a fallback chain array was set as "prefix"
|
|
|
|
* @since 5.34
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(QString usedPrefix READ usedPrefix NOTIFY usedPrefixChanged)
|
|
|
|
|
2012-01-10 12:29:35 +01:00
|
|
|
/**
|
|
|
|
* The margins of the frame, read only
|
|
|
|
* @see FrameSvgItemMargins
|
|
|
|
*/
|
2010-10-12 19:51:57 +00:00
|
|
|
Q_PROPERTY(QObject *margins READ margins CONSTANT)
|
|
|
|
|
2014-02-21 21:13:12 +01:00
|
|
|
/**
|
|
|
|
* The margins of the frame, regardless if they are enabled or not
|
|
|
|
* read only
|
|
|
|
* @see FrameSvgItemMargins
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(QObject *fixedMargins READ fixedMargins CONSTANT)
|
|
|
|
|
2012-01-10 12:29:35 +01:00
|
|
|
/**
|
|
|
|
* The borders that will be rendered, it's a flag combination of:
|
|
|
|
* NoBorder
|
|
|
|
* TopBorder
|
|
|
|
* BottomBorder
|
|
|
|
* LeftBorder
|
|
|
|
* RightBorder
|
|
|
|
*/
|
2012-08-11 19:13:21 -03:00
|
|
|
Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders WRITE setEnabledBorders NOTIFY enabledBordersChanged)
|
2010-11-05 20:50:28 +00:00
|
|
|
|
2014-10-10 17:36:44 +02:00
|
|
|
/**
|
|
|
|
* Holds whether the current svg is present in the current theme and NO fallback is involved
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(bool fromCurrentTheme READ fromCurrentTheme NOTIFY fromCurrentThemeChanged)
|
|
|
|
|
2015-03-19 11:20:01 +01:00
|
|
|
/**
|
|
|
|
* Set a color group for the FrameSvgItem.
|
|
|
|
* if the Svg uses stylesheets and has elements
|
|
|
|
* that are eithe TextColor or BackgroundColor class,
|
|
|
|
* make them use ButtonTextColor/ButtonBackgroundColor
|
|
|
|
* or ViewTextColor/ViewBackgroundColor, ComplementaryTextColor etc.
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(Plasma::Theme::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged)
|
|
|
|
|
2016-05-31 11:10:47 +02:00
|
|
|
/**
|
2016-06-01 14:47:56 +02:00
|
|
|
* Sets the image in a selected status.
|
|
|
|
* Svgs can be colored with system color themes, if the status is selected,
|
2016-05-31 11:10:47 +02:00
|
|
|
* the TextColor will become HighlightedText color and BackgroundColor
|
|
|
|
* will become HighlightColor, making the svg graphics (for instance an icon)
|
|
|
|
* will look correct together selected text
|
2016-06-01 14:47:56 +02:00
|
|
|
* @see Plasma::Svg::status
|
2016-05-31 11:10:47 +02:00
|
|
|
* @since 5.23
|
|
|
|
*/
|
2016-06-01 14:47:56 +02:00
|
|
|
Q_PROPERTY(Plasma::Svg::Status status READ status WRITE setStatus NOTIFY statusChanged)
|
2016-05-31 11:10:47 +02:00
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
public:
|
2014-08-12 21:58:17 +02:00
|
|
|
/**
|
|
|
|
* @return true if the svg has the necessary elements with the given prefix
|
|
|
|
* to draw a frame
|
|
|
|
* @param prefix the given prefix we want to check if drawable
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE bool hasElementPrefix(const QString &prefix) const;
|
|
|
|
|
|
|
|
/// @cond INTERNAL_DOCS
|
2017-12-13 07:35:58 +01:00
|
|
|
FrameSvgItem(QQuickItem *parent = nullptr);
|
2010-10-12 19:51:57 +00:00
|
|
|
~FrameSvgItem();
|
|
|
|
|
|
|
|
void setImagePath(const QString &path);
|
|
|
|
QString imagePath() const;
|
|
|
|
|
possibility to use a fallback chain as prefix
Summary:
if a framesvgitem has an array as prefix, like
FrameSvg {
prefix: ["toolbutton-hover", "hover"]
}
it will use the first available prefix, so on themes that
have toolbutton-hover, that one will be used, old themes will
continue to use "hover" as prefix
Test Plan:
tested the calendar with breeze theme has breeze-widget style
toolbuttons, with olt themes as air, the old behavior is still
there, switching on the fly works
Reviewers: davidedmundson, #plasma
Subscribers: davidedmundson, broulik, plasma-devel, #frameworks
Tags: #plasma, #frameworks
Differential Revision: https://phabricator.kde.org/D4827
2017-02-27 18:54:22 +01:00
|
|
|
void setPrefix(const QVariant &prefix);
|
|
|
|
QVariant prefix() const;
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2017-06-07 18:22:34 +02:00
|
|
|
QString usedPrefix() const;
|
|
|
|
|
2010-11-05 20:50:28 +00:00
|
|
|
void setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders);
|
|
|
|
Plasma::FrameSvg::EnabledBorders enabledBorders() const;
|
|
|
|
|
2017-08-29 11:10:19 +02:00
|
|
|
FrameSvgItemMargins *margins();
|
|
|
|
FrameSvgItemMargins *fixedMargins();
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2015-03-19 11:20:01 +01:00
|
|
|
void setColorGroup(Plasma::Theme::ColorGroup group);
|
|
|
|
Plasma::Theme::ColorGroup colorGroup() const;
|
|
|
|
|
2014-10-10 17:36:44 +02:00
|
|
|
bool fromCurrentTheme() const;
|
|
|
|
|
2016-06-01 14:47:56 +02:00
|
|
|
void setStatus(Plasma::Svg::Status status);
|
|
|
|
Plasma::Svg::Status status() const;
|
2016-05-31 11:10:47 +02:00
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
void geometryChanged(const QRectF &newGeometry,
|
2018-05-23 08:05:31 +02:00
|
|
|
const QRectF &oldGeometry) override;
|
2010-10-12 19:51:57 +00:00
|
|
|
|
2013-02-21 14:58:09 +01:00
|
|
|
/**
|
|
|
|
* Only to be used from inside this library, is not intended to be invokable
|
|
|
|
*/
|
|
|
|
Plasma::FrameSvg *frameSvg() const;
|
|
|
|
|
2018-05-23 08:05:31 +02:00
|
|
|
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
|
2014-03-05 12:14:40 +01:00
|
|
|
|
2018-02-10 01:25:13 +01:00
|
|
|
void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData & data) override;
|
2014-08-12 21:58:17 +02:00
|
|
|
|
2014-02-13 12:45:21 +01:00
|
|
|
protected:
|
2018-05-23 08:05:31 +02:00
|
|
|
void classBegin() override;
|
|
|
|
void componentComplete() override;
|
2014-02-13 12:45:21 +01:00
|
|
|
|
2014-08-12 21:58:17 +02:00
|
|
|
/// @endcond
|
|
|
|
|
2013-06-21 02:22:02 +02:00
|
|
|
Q_SIGNALS:
|
2012-08-11 19:13:21 -03:00
|
|
|
void imagePathChanged();
|
|
|
|
void prefixChanged();
|
|
|
|
void enabledBordersChanged();
|
2014-10-10 17:36:44 +02:00
|
|
|
void fromCurrentThemeChanged();
|
2015-03-19 11:20:01 +01:00
|
|
|
void colorGroupChanged();
|
2015-03-30 13:42:40 +02:00
|
|
|
void repaintNeeded();
|
2016-06-01 14:47:56 +02:00
|
|
|
void statusChanged();
|
2017-06-07 18:22:34 +02:00
|
|
|
void usedPrefixChanged();
|
2012-08-11 19:13:21 -03:00
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void doUpdate();
|
2014-01-28 15:15:55 +01:00
|
|
|
void updateDevicePixelRatio();
|
2010-10-12 19:51:57 +00:00
|
|
|
|
|
|
|
private:
|
possibility to use a fallback chain as prefix
Summary:
if a framesvgitem has an array as prefix, like
FrameSvg {
prefix: ["toolbutton-hover", "hover"]
}
it will use the first available prefix, so on themes that
have toolbutton-hover, that one will be used, old themes will
continue to use "hover" as prefix
Test Plan:
tested the calendar with breeze theme has breeze-widget style
toolbuttons, with olt themes as air, the old behavior is still
there, switching on the fly works
Reviewers: davidedmundson, #plasma
Subscribers: davidedmundson, broulik, plasma-devel, #frameworks
Tags: #plasma, #frameworks
Differential Revision: https://phabricator.kde.org/D4827
2017-02-27 18:54:22 +01:00
|
|
|
void applyPrefixes();
|
|
|
|
|
2010-10-12 19:51:57 +00:00
|
|
|
Plasma::FrameSvg *m_frameSvg;
|
|
|
|
FrameSvgItemMargins *m_margins;
|
2014-02-21 21:13:12 +01:00
|
|
|
FrameSvgItemMargins *m_fixedMargins;
|
possibility to use a fallback chain as prefix
Summary:
if a framesvgitem has an array as prefix, like
FrameSvg {
prefix: ["toolbutton-hover", "hover"]
}
it will use the first available prefix, so on themes that
have toolbutton-hover, that one will be used, old themes will
continue to use "hover" as prefix
Test Plan:
tested the calendar with breeze theme has breeze-widget style
toolbuttons, with olt themes as air, the old behavior is still
there, switching on the fly works
Reviewers: davidedmundson, #plasma
Subscribers: davidedmundson, broulik, plasma-devel, #frameworks
Tags: #plasma, #frameworks
Differential Revision: https://phabricator.kde.org/D4827
2017-02-27 18:54:22 +01:00
|
|
|
QStringList m_prefixes;
|
2014-03-05 12:14:40 +01:00
|
|
|
bool m_textureChanged;
|
2014-07-15 16:28:41 +02:00
|
|
|
bool m_sizeChanged;
|
2014-07-16 17:01:05 +02:00
|
|
|
bool m_fastPath;
|
2010-10-12 19:51:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|