Changeset View
Changeset View
Standalone View
Standalone View
src/mnemonicattached.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2017 by Marco Martin <mart@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #ifndef MNEMONICATTACHED_H | ||||
21 | #define MNEMONICATTACHED_H | ||||
22 | | ||||
23 | #include <QtQml> | ||||
24 | #include <QObject> | ||||
25 | | ||||
26 | class QQuickItem; | ||||
27 | | ||||
28 | class MnemonicAttached : public QObject | ||||
29 | { | ||||
30 | Q_OBJECT | ||||
31 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) | ||||
32 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) | ||||
33 | Q_PROPERTY(QString decoratedLabel READ decoratedLabel NOTIFY decoratedLabelChanged) | ||||
34 | Q_PROPERTY(QKeySequence sequence READ sequence NOTIFY sequenceChanged) | ||||
35 | | ||||
36 | public: | ||||
37 | | ||||
38 | explicit MnemonicAttached(QObject *parent = 0); | ||||
39 | ~MnemonicAttached(); | ||||
broulik: Use `Q_ENUM` | |||||
40 | | ||||
41 | void setLabel(const QString &text); | ||||
42 | QString label() const; | ||||
43 | | ||||
44 | void setEnabled(bool enabled); | ||||
45 | bool enabled() const; | ||||
46 | | ||||
47 | QString decoratedLabel() const; | ||||
48 | | ||||
49 | QKeySequence sequence(); | ||||
broulik: `nullptr` | |||||
50 | | ||||
51 | //QML attached property | ||||
52 | static MnemonicAttached *qmlAttachedProperties(QObject *object); | ||||
53 | | ||||
54 | protected: | ||||
55 | bool eventFilter(QObject *watched, QEvent *e); | ||||
56 | void updateSequence(); | ||||
57 | | ||||
58 | Q_SIGNALS: | ||||
59 | void labelChanged(); | ||||
60 | void enabledChanged(); | ||||
61 | void sequenceChanged(); | ||||
62 | void decoratedLabelChanged(); | ||||
63 | | ||||
64 | private: | ||||
65 | void calculateWeights(); | ||||
66 | | ||||
67 | //TODO: to have support for DIALOG_BUTTON_EXTRA_WEIGHT etc, a type enum should be exported | ||||
68 | enum { | ||||
69 | // Additional weight for first character in string | ||||
70 | FIRST_CHARACTER_EXTRA_WEIGHT = 50, | ||||
71 | // Additional weight for the beginning of a word | ||||
72 | WORD_BEGINNING_EXTRA_WEIGHT = 50, | ||||
73 | // Additional weight for the dialog buttons (large, we basically never want these reassigned) | ||||
74 | DIALOG_BUTTON_EXTRA_WEIGHT = 300, | ||||
75 | // Additional weight for a 'wanted' accelerator ie string with '&' | ||||
76 | WANTED_ACCEL_EXTRA_WEIGHT = 150, | ||||
77 | // Default weight for an 'action' widget (ie, pushbuttons) | ||||
78 | ACTION_ELEMENT_WEIGHT = 50, | ||||
79 | // Default weight for checkable group boxes (low priority) | ||||
80 | CHECKABLE_GROUP_BOX_WEIGHT = 20, | ||||
81 | // Default weight for menu titles | ||||
82 | MENU_TITLE_WEIGHT = 250 | ||||
83 | }; | ||||
84 | | ||||
85 | //order word letters by weight | ||||
86 | int m_weight = 0; | ||||
87 | QMap<int, QChar> m_weights; | ||||
88 | | ||||
89 | QString m_label; | ||||
90 | QString m_actualDecoratedLabel; | ||||
91 | QString m_richTextLabel; | ||||
92 | bool m_enabled = true; | ||||
93 | | ||||
94 | //sequence->weight->widget | ||||
95 | static QHash<QKeySequence, MnemonicAttached *> s_sequenceToObject; | ||||
96 | static QHash<MnemonicAttached *, QKeySequence> s_objectToSequence; | ||||
97 | }; | ||||
98 | | ||||
99 | QML_DECLARE_TYPEINFO(MnemonicAttached, QML_HAS_ATTACHED_PROPERTIES) | ||||
100 | | ||||
101 | #endif // MnemonicATTACHED_H | ||||
This can go with D8827, right? hein: This can go with D8827, right? | |||||
no, mnemonics support is here, D8827 is the part in qqc2-desktop-style, another repo mart: no, mnemonics support is here, D8827 is the part in qqc2-desktop-style, another repo | |||||
hein: Ah, ok, I guess I thought window-level stuff might happen there. | |||||
yeah, i plan to add another granularity level to separe mnemonics per-window but since adds more complexity, i agreed beforehand to not make the diff grow more, so i'll push this beforehand and then give it the per-window support mart: yeah, i plan to add another granularity level to separe mnemonics per-window but since adds… |
Use Q_ENUM