diff --git a/src/delegaterecycler.h b/src/delegaterecycler.h index 5a5f3c52..e03eda1d 100644 --- a/src/delegaterecycler.h +++ b/src/delegaterecycler.h @@ -1,87 +1,87 @@ /* * Copyright 2018 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library 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 DELEGATERECYCLER_H #define DELEGATERECYCLER_H #include #include #include class DelegateCache; /** * This class may be used as a delegate of a ListView or a GridView in the case * the intended delegate is a bit heavy, with many objects inside. * This will ensure the delegate instances will be put back in a common pool after * destruction, so when scrolling a big list, the delegates from old delete items will * be taken from the pool and reused, minimizing the need of instantiating new objects * and deleting old ones. It ensures scrolling of lists with heavy delegates is * smoother and helps with memory fragmentations as well. * * NOTE: CardListView and CardGridView are already using this recycler, so do NOT use it * as a delegate for those 2 views. * Also, do NOT use this with a Repeater. * @since 2.4 */ class DelegateRecycler : public QQuickItem { Q_OBJECT /** * The Component the actual delegates will be built from. * Note: the component may not be a child of this object, therefore it can't be * declared inside the DelegateRecycler declaration. * The DelegateRecycler will not take ownership of the delegate Component, so it's up * to the caller to delete it (usually with the normal child/parent relationship) */ Q_PROPERTY(QQmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceComponentChanged) public: - DelegateRecycler(QQuickItem *parent=0); + DelegateRecycler(QQuickItem *parent = nullptr); ~DelegateRecycler(); QQmlComponent *sourceComponent() const; void setSourceComponent(QQmlComponent *component); void resetSourceComponent(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void updateHints(); void updateSize(bool parentResized); Q_SIGNALS: void sourceComponentChanged(); private Q_SLOTS: void syncIndex(); void syncModel(); void syncModelData(); private: QPointer m_sourceComponent; QPointer m_item; QObject *m_propertiesTracker = nullptr; bool m_updatingSize = false; }; #endif diff --git a/src/desktopicon.h b/src/desktopicon.h index 4740b603..18948775 100644 --- a/src/desktopicon.h +++ b/src/desktopicon.h @@ -1,115 +1,115 @@ /* * Copyright 2011 Marco Martin * Copyright 2014 Aleix Pol Gonzalez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library 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 DESKTOPICON_H #define DESKTOPICON_H #include #include #include #include class QNetworkAccessManager; class QNetworkReply; namespace Kirigami { class PlatformTheme; } class DesktopIcon : public QQuickItem { Q_OBJECT Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) Q_PROPERTY(int implicitWidth READ implicitWidth CONSTANT) Q_PROPERTY(int implicitHeight READ implicitHeight CONSTANT) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) Q_PROPERTY(bool valid READ valid NOTIFY validChanged) Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) Q_PROPERTY(bool isMask READ isMask WRITE setIsMask NOTIFY isMaskChanged) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) public: - DesktopIcon(QQuickItem *parent=0); + DesktopIcon(QQuickItem *parent = nullptr); ~DesktopIcon(); void setSource(const QVariant &source); QVariant source() const; int implicitWidth() const; int implicitHeight() const; void setSmooth(const bool smooth); bool smooth() const; void setEnabled(bool enabled = true); void setActive(bool active = true); bool active() const; bool valid() const; void setSelected(bool selected = true); bool selected() const; void setIsMask(bool mask); bool isMask() const; void setColor(const QColor &color); QColor color() const; QSGNode* updatePaintNode(QSGNode* node, UpdatePaintNodeData* data) override; //HACKY but we need the base path for internal icons registered by kirigamiplugin itself static QString s_internalIconPath; Q_SIGNALS: void sourceChanged(); void smoothChanged(); void enabledChanged(); void activeChanged(); void validChanged(); void selectedChanged(); void isMaskChanged(); void colorChanged(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; QImage findIcon(const QSize& size); void handleFinished(QNetworkAccessManager* qnam, QNetworkReply* reply); void handleReadyRead(QNetworkReply* reply); QIcon::Mode iconMode() const; private: Kirigami::PlatformTheme *m_theme = nullptr; QPointer m_networkReply; QVariant m_source; bool m_smooth; bool m_changed; bool m_active; bool m_selected; bool m_isMask; QImage m_loadedImage; QColor m_color = Qt::transparent; }; #endif diff --git a/src/libkirigami/basictheme_p.h b/src/libkirigami/basictheme_p.h index b059f263..c9688c91 100644 --- a/src/libkirigami/basictheme_p.h +++ b/src/libkirigami/basictheme_p.h @@ -1,99 +1,99 @@ /* * Copyright (C) 2017 by Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library 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 BASICTHEME_H #define BASICTHEME_H #include "platformtheme.h" #include #include #include #include namespace Kirigami { class BasicTheme; class BasicThemeDeclarative { public: BasicThemeDeclarative(); virtual ~BasicThemeDeclarative(); QObject *instance(const BasicTheme *theme); QTimer *m_colorSyncTimer; private: QUrl m_qmlPath; QObject *m_declarativeBasicTheme = nullptr; }; class BasicTheme : public PlatformTheme { Q_OBJECT // colors Q_PROPERTY(QColor buttonTextColor READ buttonTextColor NOTIFY colorsChanged) Q_PROPERTY(QColor buttonBackgroundColor READ buttonBackgroundColor NOTIFY colorsChanged) Q_PROPERTY(QColor buttonHoverColor READ buttonHoverColor NOTIFY colorsChanged) Q_PROPERTY(QColor buttonFocusColor READ buttonFocusColor NOTIFY colorsChanged) Q_PROPERTY(QColor viewTextColor READ viewTextColor NOTIFY colorsChanged) Q_PROPERTY(QColor viewBackgroundColor READ viewBackgroundColor NOTIFY colorsChanged) Q_PROPERTY(QColor viewHoverColor READ viewHoverColor NOTIFY colorsChanged) Q_PROPERTY(QColor viewFocusColor READ viewFocusColor NOTIFY colorsChanged) public: - explicit BasicTheme(QObject *parent = 0); + explicit BasicTheme(QObject *parent = nullptr); ~BasicTheme(); void syncColors(); QColor buttonTextColor() const; QColor buttonBackgroundColor() const; QColor buttonHoverColor() const; QColor buttonFocusColor() const; QColor viewTextColor() const; QColor viewBackgroundColor() const; QColor viewHoverColor() const; QColor viewFocusColor() const; static BasicThemeDeclarative *basicThemeDeclarative(); Q_SIGNALS: void colorsChanged(); private: inline void syncCustomColorsToQML(); //legacy colors QColor m_buttonTextColor; QColor m_buttonBackgroundColor; QColor m_buttonHoverColor; QColor m_buttonFocusColor; QColor m_viewTextColor; QColor m_viewBackgroundColor; QColor m_viewHoverColor; QColor m_viewFocusColor; }; } #endif // BASICTHEME_H diff --git a/src/libkirigami/platformtheme.h b/src/libkirigami/platformtheme.h index d93a1c0e..466ada4f 100644 --- a/src/libkirigami/platformtheme.h +++ b/src/libkirigami/platformtheme.h @@ -1,270 +1,270 @@ /* * Copyright (C) 2017 by Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library 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 PLATFORMTHEME_H #define PLATFORMTHEME_H #include #include #include #include #ifndef KIRIGAMI_BUILD_TYPE_STATIC #include #endif namespace Kirigami { class PlatformThemePrivate; /** * @class PlatformTheme platformtheme.h PlatformTheme * * This class is the base for color management in Kirigami, * different platforms can reimplement this class to integrate with * system platform colors of a given platform */ #ifdef KIRIGAMI_BUILD_TYPE_STATIC class PlatformTheme : public QObject #else class KIRIGAMI2_EXPORT PlatformTheme : public QObject #endif { Q_OBJECT /** * This enumeration describes the color set for which a color is being selected. * * Color sets define a color "environment", suitable for drawing all parts of a * given region. Colors from different sets should not be combined. */ Q_PROPERTY(ColorSet colorSet READ colorSet WRITE setColorSet NOTIFY colorSetChanged) /** * This enumeration describes the color group used to generate the colors. * The enum value is based upon QPalette::CpolorGroup and has the same values. * It's redefined here in order to make it work with QML * @since 4.43 */ Q_PROPERTY(ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged) /** * If true, the colorSet will be inherited from the colorset of a theme of one * of the ancestor items * default: true */ Q_PROPERTY(bool inherit READ inherit WRITE setInherit NOTIFY inheritChanged) // foreground colors /** * Color for normal foregrounds, usually text, but not limited to it, * anything that should be painted with a clear contrast should use this color */ Q_PROPERTY(QColor textColor READ textColor WRITE setCustomTextColor RESET setCustomTextColor NOTIFY colorsChanged) /** * Foreground color for disabled areas, usually a mid-gray */ Q_PROPERTY(QColor disabledTextColor READ disabledTextColor WRITE setCustomDisabledTextColor RESET setCustomDisabledTextColor NOTIFY colorsChanged) /** * Color for text that has been highlighted, often is a light color while normal text is dark */ Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setCustomHighlightedTextColor RESET setCustomHighlightedTextColor NOTIFY colorsChanged) /** * Foreground for areas that are active or requesting attention */ Q_PROPERTY(QColor activeTextColor READ activeTextColor WRITE setCustomActiveTextColor RESET setCustomActiveTextColor NOTIFY colorsChanged) /** * Color for links */ Q_PROPERTY(QColor linkColor READ linkColor WRITE setCustomLinkColor RESET setCustomLinkColor NOTIFY colorsChanged) /** * Color for visited links, usually a bit darker than linkColor */ Q_PROPERTY(QColor visitedLinkColor READ visitedLinkColor WRITE setCustomVisitedLinkColor RESET setCustomVisitedLinkColor NOTIFY colorsChanged) /** * Foreground color for negative areas, such as critical error text */ Q_PROPERTY(QColor negativeTextColor READ negativeTextColor WRITE setCustomNegativeTextColor RESET setCustomNegativeTextColor NOTIFY colorsChanged) /** * Foreground color for neutral areas, such as warning texts (but not critical) */ Q_PROPERTY(QColor neutralTextColor READ neutralTextColor WRITE setCustomNeutralTextColor RESET setCustomNeutralTextColor NOTIFY colorsChanged) /** * Success messages, trusted content */ Q_PROPERTY(QColor positiveTextColor READ positiveTextColor WRITE setCustomPositiveTextColor RESET setCustomPositiveTextColor NOTIFY colorsChanged) //background colors /** * The generic background color */ Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setCustomBackgroundColor RESET setCustomBackgroundColor NOTIFY colorsChanged) /** * The background color for selected areas */ Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setCustomHighlightColor RESET setCustomHighlightColor NOTIFY colorsChanged) //decoration colors /** * A decoration color that indicates active focus */ Q_PROPERTY(QColor focusColor READ focusColor WRITE setCustomFocusColor RESET setCustomFocusColor NOTIFY colorsChanged) /** * A decoration color that indicates mouse hovering */ Q_PROPERTY(QColor hoverColor READ hoverColor WRITE setCustomHoverColor RESET setCustomHoverColor NOTIFY colorsChanged) // font and palette Q_PROPERTY(QFont defaultFont READ defaultFont NOTIFY defaultFontChanged) //Active palette Q_PROPERTY(QPalette palette READ palette NOTIFY paletteChanged) public: enum ColorSet { View = 0, /** Color set for item views, usually the lightest of all */ Window, /** Default Color set for windows and "chrome" areas */ Button, /** Color set used by buttons */ Selection, /** Color set used by selectged areas */ Tooltip, /** Color set used by tooltips */ Complementary /** Color set meant to be complementary to Window: usually is a dark theme for light themes */ }; Q_ENUM(ColorSet) enum ColorGroup { Disabled = QPalette::Disabled, Active = QPalette::Active, Inactive = QPalette::Inactive, Normal = QPalette::Normal }; Q_ENUM(ColorGroup) - explicit PlatformTheme(QObject *parent = 0); + explicit PlatformTheme(QObject *parent = nullptr); ~PlatformTheme(); void setColorSet(PlatformTheme::ColorSet); PlatformTheme::ColorSet colorSet() const; void setColorGroup(PlatformTheme::ColorGroup); PlatformTheme::ColorGroup colorGroup() const; bool inherit() const; void setInherit(bool inherit); //foreground colors QColor textColor() const; QColor disabledTextColor() const; QColor highlightedTextColor() const; QColor activeTextColor() const; QColor linkColor() const; QColor visitedLinkColor() const; QColor negativeTextColor() const; QColor neutralTextColor() const; QColor positiveTextColor() const; //background colors QColor backgroundColor() const; QColor highlightColor() const; //TODO: add active/positive/neutral/negative backgrounds? //decoration colors QColor focusColor() const; QColor hoverColor() const; QFont defaultFont() const; //this may is used by the desktop QQC2 to set the styleoption palettes QPalette palette() const; //this will be used by desktopicon to fetch icons with KIconLoader virtual Q_INVOKABLE QIcon iconFromTheme(const QString &name, const QColor &customColor = Qt::transparent); //foreground colors void setCustomTextColor(const QColor &color = QColor()); void setCustomDisabledTextColor(const QColor &color = QColor()); void setCustomHighlightedTextColor(const QColor &color = QColor()); void setCustomActiveTextColor(const QColor &color = QColor()); void setCustomLinkColor(const QColor &color = QColor()); void setCustomVisitedLinkColor(const QColor &color = QColor()); void setCustomNegativeTextColor(const QColor &color = QColor()); void setCustomNeutralTextColor(const QColor &color = QColor()); void setCustomPositiveTextColor(const QColor &color = QColor()); //background colors void setCustomBackgroundColor(const QColor &color = QColor()); void setCustomHighlightColor(const QColor &color = QColor()); //decoration colors void setCustomFocusColor(const QColor &color = QColor()); void setCustomHoverColor(const QColor &color = QColor()); //QML attached property static PlatformTheme *qmlAttachedProperties(QObject *object); Q_SIGNALS: //TODO: parameters to signals as this is also a c++ api void colorsChanged(); void defaultFontChanged(const QFont &font); void colorSetChanged(Kirigami::PlatformTheme::ColorSet colorSet); void colorGroupChanged(Kirigami::PlatformTheme::ColorGroup colorGroup); void paletteChanged(const QPalette &pal); void inheritChanged(bool inherit); protected: //Setters, not accessible from QML but from implementations //foreground colors void setTextColor(const QColor &color); void setDisabledTextColor(const QColor &color); void setHighlightedTextColor(const QColor &color); void setActiveTextColor(const QColor &color); void setLinkColor(const QColor &color); void setVisitedLinkColor(const QColor &color); void setNegativeTextColor(const QColor &color); void setNeutralTextColor(const QColor &color); void setPositiveTextColor(const QColor &color); //background colors void setBackgroundColor(const QColor &color); void setHighlightColor(const QColor &color); //decoration colors void setFocusColor(const QColor &color); void setHoverColor(const QColor &color); void setDefaultFont(const QFont &defaultFont); void setPalette(const QPalette &palette); private: PlatformThemePrivate *d; friend class PlatformThemePrivate; }; } QML_DECLARE_TYPEINFO(Kirigami::PlatformTheme, QML_HAS_ATTACHED_PROPERTIES) #endif // PLATFORMTHEME_H diff --git a/src/libkirigami/tabletmodewatcher.h b/src/libkirigami/tabletmodewatcher.h index 56bd803b..f8ca1fe9 100644 --- a/src/libkirigami/tabletmodewatcher.h +++ b/src/libkirigami/tabletmodewatcher.h @@ -1,88 +1,88 @@ /* * Copyright 2018 Marco Martin * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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, see . * */ #ifndef KIRIGAMI_TABLETMODEWATCHER #define KIRIGAMI_TABLETMODEWATCHER #include #ifndef KIRIGAMI_BUILD_TYPE_STATIC #include #endif namespace Kirigami { class TabletModeWatcherPrivate; /** * This class reports on the status of certain transformable * devices which can be both tablets and laptops at the same time, * with a detachable keyboard. * It reports whether the device supports a tablet mode and if * the device is currently in such mode or not, emitting a signal * when the user switches. */ #ifdef KIRIGAMI_BUILD_TYPE_STATIC class TabletModeWatcher : public QObject #else class KIRIGAMI2_EXPORT TabletModeWatcher : public QObject #endif { Q_OBJECT Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged) Q_PROPERTY(bool tabletMode READ isTabletMode NOTIFY tabletModeChanged) public: ~TabletModeWatcher(); static TabletModeWatcher *self(); /** * @returns true if the device supports a tablet mode and has a switch * to report when the device has been transformed. * For debug purposes, if either the environment variable QT_QUICK_CONTROLS_MOBILE * or KDE_KIRIGAMI_TABLET_MODE are set to true, isTabletModeAvailable will be true */ bool isTabletModeAvailable() const; /** * @returns true if the machine is now in tablet mode, such as the * laptop keyboard flipped away or detached. * Note that this doesn't mean exactly a tablet form factor, but * that the preferred input mode for the device is the touch screen * and that pointer and keyboard are either secondary or not available. * * For debug purposes, if either the environment variable QT_QUICK_CONTROLS_MOBILE * or KDE_KIRIGAMI_TABLET_MODE are set to true, isTabletMode will be true */ bool isTabletMode() const; Q_SIGNALS: void tabletModeAvailableChanged(bool tabletModeAvailable); void tabletModeChanged(bool tabletMode); private: - TabletModeWatcher(QObject *parent = 0); + TabletModeWatcher(QObject *parent = nullptr); TabletModeWatcherPrivate *d; friend class TabletModeWatcherSingleton; }; } #endif // KIRIGAMI_TABLETMODEWATCHER diff --git a/src/mnemonicattached.h b/src/mnemonicattached.h index 2425ee2a..ebdf1752 100644 --- a/src/mnemonicattached.h +++ b/src/mnemonicattached.h @@ -1,169 +1,169 @@ /* * Copyright (C) 2017 by Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library 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 MNEMONICATTACHED_H #define MNEMONICATTACHED_H #include #include #include class QQuickItem; /** * This Attached property is used to calculate automated keyboard sequences * to trigger actions based upon their text: if an "&" mnemonic is * used (ie "&Ok"), the system will attempt to assign the desired letter giving * it priority, otherwise a letter among the ones in the label will be used if * possible and not conflicting. * Different kinds of controls will have different priorities in assigning the * shortcut: for instance the "Ok/Cancel" buttons in a dialog will have priority * over fields of a FormLayout. * @see ControlType * * Usually the developer shouldn't use this directly as base components * already use this, but only when implementing a custom graphical Control. * @since 2.3 */ class MnemonicAttached : public QObject { Q_OBJECT /** * The label of the control we want to compute a mnemonic for, instance * "Label:" or "&Ok" */ Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) /** * The user-visible final label, which will have the shortcut letter underlined, * such as "<u>O</u>k" */ Q_PROPERTY(QString richTextLabel READ richTextLabel NOTIFY richTextLabelChanged) /** * The label with an "&" mnemonic in the place which will have the shortcut * assigned, regardless the & wasassigned by the user or automatically generated. */ Q_PROPERTY(QString mnemonicLabel READ mnemonicLabel NOTIFY mnemonicLabelChanged) /** * Only if true this mnemonic will be considered for the global assignment * default: true */ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) /** * the type of control this mnemonic is attached: different types of controls have different importance and priority for shortcut assignment. * @see ControlType */ Q_PROPERTY(MnemonicAttached::ControlType controlType READ controlType WRITE setControlType NOTIFY controlTypeChanged) /** * The final key sequence assigned, if any: it will be Alt+alphanumeric char */ Q_PROPERTY(QKeySequence sequence READ sequence NOTIFY sequenceChanged) public: enum ControlType { ActionElement, /** pushbuttons, checkboxes etc */ DialogButton, /** buttons for dialogs */ MenuItem, /** Menu items */ FormLabel, /** Buddy label in a FormLayout*/ SecondaryControl /** Other controls that are considered not much important and low priority for shortcuts */ }; Q_ENUM(ControlType) - explicit MnemonicAttached(QObject *parent = 0); + explicit MnemonicAttached(QObject *parent = nullptr); ~MnemonicAttached(); void setLabel(const QString &text); QString label() const; QString richTextLabel() const; QString mnemonicLabel() const; void setEnabled(bool enabled); bool enabled() const; void setControlType(MnemonicAttached::ControlType controlType); ControlType controlType() const; QKeySequence sequence(); //QML attached property static MnemonicAttached *qmlAttachedProperties(QObject *object); protected: bool eventFilter(QObject *watched, QEvent *e); void updateSequence(); Q_SIGNALS: void labelChanged(); void enabledChanged(); void sequenceChanged(); void richTextLabelChanged(); void mnemonicLabelChanged(); void controlTypeChanged(); private: void calculateWeights(); //TODO: to have support for DIALOG_BUTTON_EXTRA_WEIGHT etc, a type enum should be exported enum { // Additional weight for first character in string FIRST_CHARACTER_EXTRA_WEIGHT = 50, // Additional weight for the beginning of a word WORD_BEGINNING_EXTRA_WEIGHT = 50, // Additional weight for a 'wanted' accelerator ie string with '&' WANTED_ACCEL_EXTRA_WEIGHT = 150, // Default weight for an 'action' widget (ie, pushbuttons) ACTION_ELEMENT_WEIGHT = 50, // Additional weight for the dialog buttons (large, we basically never want these reassigned) DIALOG_BUTTON_EXTRA_WEIGHT = 300, // Weight for FormLayout labels (low) FORM_LABEL_WEIGHT = 20, // Weight for Secondary controls which are considered less important (low) SECONDARY_CONTROL_WEIGHT = 10, // Default weight for menu items MENU_ITEM_WEIGHT = 250 }; //order word letters by weight int m_weight = 0; int m_baseWeight = 0; ControlType m_controlType = SecondaryControl; QMap m_weights; QString m_label; QString m_actualRichTextLabel; QString m_richTextLabel; QString m_mnemonicLabel; bool m_enabled = true; QPointer m_window; //global mapping of mnemonics //TODO: map by QWindow static QHash s_sequenceToObject; static QHash s_objectToSequence; }; QML_DECLARE_TYPEINFO(MnemonicAttached, QML_HAS_ATTACHED_PROPERTIES) #endif // MnemonicATTACHED_H diff --git a/src/settings.h b/src/settings.h index 40b05232..b918d1d9 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,97 +1,97 @@ /* * Copyright 2016 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library 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 SETTINGS_H #define SETTINGS_H #include /** * This class contains global kirigami settings about the current device setup * It is exposed to QML as the singleton "Settings" */ class Settings : public QObject { Q_OBJECT /** * True if the system can dynamically enter in tablet mode * (or the device is actually a tablet). * such as transformable laptops that support keyboard detachment */ Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged) /** * True if we are running on a small mobile device such as a mobile phone * This is used when we want to do specific adaptations to our UI for * small screen form factors, such as having bigger touch areas. */ Q_PROPERTY(bool isMobile READ isMobile NOTIFY isMobileChanged) /** * True if the device we are running on is behaving like a tablet: * Note that this doesn't mean exactly a tablet form factor, but * that the preferred input mode for the device is the touch screen * and that pointer and keyboard are either secondary or not available. */ Q_PROPERTY(bool tabletMode READ tabletMode NOTIFY tabletModeChanged) /** * name of the QtQuickControls2 style we are using, * for instance org.kde.desktop, Plasma, Material, Universal etc */ Q_PROPERTY(QString style READ style CONSTANT) //TODO: make this adapt without file watchers? /** * How many lines of text the mouse wheel should scroll */ Q_PROPERTY(int mouseWheelScrollLines READ mouseWheelScrollLines CONSTANT) public: - Settings(QObject *parent=0); + Settings(QObject *parent = nullptr); ~Settings(); void setTabletModeAvailable(bool mobile); bool isTabletModeAvailable() const; void setIsMobile(bool mobile); bool isMobile() const; void setTabletMode(bool tablet); bool tabletMode() const; QString style() const; void setStyle(const QString &style); int mouseWheelScrollLines() const; Q_SIGNALS: void tabletModeAvailableChanged(); void tabletModeChanged(); void isMobileChanged(); private: QString m_style; int m_scrollLines = 0; bool m_tabletModeAvailable : 1; bool m_mobile : 1; bool m_tabletMode : 1; }; #endif