Skip to content

Commit 3518ff3

Browse files
Color picker: add alpha control where appropriate
- `IInteractive::selectColor` gets an `allowAlpha` parameter - `ColorPicker` gets a property whose value is passed to this new parameter - When alpha is 0 and the color dialog is launched, the alpha is changed to 255 in the color dialog, to prevent confusion ("Hm, I chose a color but I still see nothing...") Co-Authored-By: Casper Jeukendrup <[email protected]>
1 parent 08261ca commit 3518ff3

File tree

18 files changed

+80
-74
lines changed

18 files changed

+80
-74
lines changed

src/appshell/qml/DevTools/Gallery/GeneralComponentsGallery.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ Rectangle {
372372
width: 200
373373

374374
color: "black"
375+
allowAlpha: true
375376

376377
onNewColorSelected: function(newColor) {
377378
color = newColor

src/appshell/qml/DevTools/Preferences/SettingsPage.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ ColumnLayout {
185185

186186
anchors.fill: parent
187187
color: val
188+
allowAlpha: true
188189

189190
onNewColorSelected: function(newColor) {
190191
changed(newColor)

src/framework/autobot/internal/autobotinteractive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ io::paths_t AutobotInteractive::selectMultipleDirectories(const std::string& tit
138138
return m_real->selectMultipleDirectories(title, dir, initialDirectories);
139139
}
140140

141-
async::Promise<Color> AutobotInteractive::selectColor(const Color& color, const std::string& title)
141+
async::Promise<Color> AutobotInteractive::selectColor(const Color& color, const std::string& title, bool allowAlpha)
142142
{
143-
return m_real->selectColor(color, title);
143+
return m_real->selectColor(color, title, allowAlpha);
144144
}
145145

146146
bool AutobotInteractive::isSelectColorOpened() const

src/framework/autobot/internal/autobotinteractive.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* You should have received a copy of the GNU General Public License
2020
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2121
*/
22-
#ifndef MUSE_AUTOBOT_AUTOBOTINTERACTIVE_H
23-
#define MUSE_AUTOBOT_AUTOBOTINTERACTIVE_H
22+
23+
#pragma once
2424

2525
#include <memory>
2626

@@ -36,37 +36,37 @@ class AutobotInteractive : public IInteractive
3636
std::shared_ptr<IInteractive> realInteractive() const;
3737

3838
Result questionSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons, int defBtn = int(Button::NoButton),
39-
const Options& options = {}, const std::string& dialogTitle = "") override;
39+
const Options& options = {}, const std::string& dialogTitle = {}) override;
4040

4141
async::Promise<Result> question(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons,
4242
int defBtn = int(Button::NoButton), const Options& options = {},
43-
const std::string& dialogTitle = "") override;
43+
const std::string& dialogTitle = {}) override;
4444

4545
ButtonData buttonData(Button b) const override;
4646

4747
// info
4848
Result infoSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons, int defBtn = int(Button::NoButton),
49-
const Options& options = {}, const std::string& dialogTitle = "") override;
49+
const Options& options = {}, const std::string& dialogTitle = {}) override;
5050

5151
async::Promise<Result> info(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
5252
int defBtn = int(Button::NoButton), const Options& options = {},
53-
const std::string& dialogTitle = "") override;
53+
const std::string& dialogTitle = {}) override;
5454

5555
// warning
5656
Result warningSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons, int defBtn = int(Button::NoButton),
57-
const Options& options = {}, const std::string& dialogTitle = "") override;
57+
const Options& options = {}, const std::string& dialogTitle = {}) override;
5858

5959
async::Promise<Result> warning(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
6060
int defBtn = int(Button::NoButton), const Options& options = {},
61-
const std::string& dialogTitle = "") override;
61+
const std::string& dialogTitle = {}) override;
6262

6363
// error
6464
Result errorSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons, int defBtn = int(Button::NoButton),
65-
const Options& options = {}, const std::string& dialogTitle = "") override;
65+
const Options& options = {}, const std::string& dialogTitle = {}) override;
6666

6767
async::Promise<Result> error(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
6868
int defBtn = int(Button::NoButton), const Options& options = {},
69-
const std::string& dialogTitle = "") override;
69+
const std::string& dialogTitle = {}) override;
7070

7171
// progress
7272
void showProgress(const std::string& title, Progress progress) override;
@@ -84,7 +84,7 @@ class AutobotInteractive : public IInteractive
8484
io::paths_t selectMultipleDirectories(const std::string& title, const io::path_t& dir, const io::paths_t& initialDirectories) override;
8585

8686
// color
87-
async::Promise<Color> selectColor(const Color& color = Color::WHITE, const std::string& title = "") override;
87+
async::Promise<Color> selectColor(const Color& color = Color::WHITE, const std::string& title = {}, bool allowAlpha = false) override;
8888
bool isSelectColorOpened() const override;
8989

9090
// custom
@@ -125,5 +125,3 @@ class AutobotInteractive : public IInteractive
125125

126126
using AutobotInteractivePtr = std::shared_ptr<AutobotInteractive>;
127127
}
128-
129-
#endif // MUSE_AUTOBOT_AUTOBOTINTERACTIVE_H

src/framework/global/iinteractive.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* You should have received a copy of the GNU General Public License
2020
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2121
*/
22-
#ifndef MUSE_GLOBAL_IINTERACTIVE_H
23-
#define MUSE_GLOBAL_IINTERACTIVE_H
22+
23+
#pragma once
2424

2525
#include "modularity/imoduleinterface.h"
2626
#include "io/path.h"
@@ -166,45 +166,45 @@ class IInteractive : MODULE_EXPORT_INTERFACE
166166
// question
167167
virtual async::Promise<Result> question(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons,
168168
int defBtn = int(Button::NoButton), const Options& options = {},
169-
const std::string& dialogTitle = "") = 0;
169+
const std::string& dialogTitle = {}) = 0;
170170

171171
async::Promise<Result> question(const std::string& contentTitle, const std::string& text, const Buttons& buttons,
172-
Button defBtn = Button::NoButton, const Options& options = {}, const std::string& dialogTitle = "")
172+
Button defBtn = Button::NoButton, const Options& options = {}, const std::string& dialogTitle = {})
173173
{
174174
return question(contentTitle, Text(text), buttonDataList(buttons), (int)defBtn, options, dialogTitle);
175175
}
176176

177177
// info
178178
virtual async::Promise<Result> info(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
179179
int defBtn = int(Button::NoButton), const Options& options = {},
180-
const std::string& dialogTitle = "") = 0;
180+
const std::string& dialogTitle = {}) = 0;
181181

182182
async::Promise<Result> info(const std::string& contentTitle, const std::string& text, const Buttons& buttons,
183-
Button defBtn, const Options& options = {}, const std::string& dialogTitle = "")
183+
Button defBtn, const Options& options = {}, const std::string& dialogTitle = {})
184184
{
185185
return info(contentTitle, Text(text), buttonDataList(buttons), (int)defBtn, options, dialogTitle);
186186
}
187187

188188
// warning
189189
virtual async::Promise<Result> warning(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
190190
int defBtn = int(Button::NoButton), const Options& options = { WithIcon },
191-
const std::string& dialogTitle = "") = 0;
191+
const std::string& dialogTitle = {}) = 0;
192192

193193
async::Promise<Result> warning(const std::string& contentTitle, const std::string& text, const Buttons& buttons,
194194
Button defBtn = Button::NoButton, const Options& options = { WithIcon },
195-
const std::string& dialogTitle = "")
195+
const std::string& dialogTitle = {})
196196
{
197197
return warning(contentTitle, Text(text), buttonDataList(buttons), (int)defBtn, options, dialogTitle);
198198
}
199199

200200
// error
201201
virtual async::Promise<Result> error(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
202202
int defBtn = int(Button::NoButton), const Options& options = { WithIcon },
203-
const std::string& dialogTitle = "") = 0;
203+
const std::string& dialogTitle = {}) = 0;
204204

205205
async::Promise<Result> error(const std::string& contentTitle, const std::string& text, const Buttons& buttons,
206206
Button defBtn = Button::NoButton, const Options& options = { WithIcon },
207-
const std::string& dialogTitle = "")
207+
const std::string& dialogTitle = {})
208208
{
209209
return error(contentTitle, Text(text), buttonDataList(buttons), (int)defBtn, options, dialogTitle);
210210
}
@@ -226,7 +226,8 @@ class IInteractive : MODULE_EXPORT_INTERFACE
226226
const io::paths_t& selectedDirectories) = 0;
227227

228228
// color
229-
virtual async::Promise<Color> selectColor(const Color& color = Color::WHITE, const std::string& title = "") = 0;
229+
virtual async::Promise<Color> selectColor(const Color& color = Color::WHITE, const std::string& title = {},
230+
bool allowAlpha = false) = 0;
230231
virtual bool isSelectColorOpened() const = 0;
231232

232233
// custom
@@ -262,39 +263,39 @@ class IInteractive : MODULE_EXPORT_INTERFACE
262263
//! NOTE Please don't use this
263264
//! =================================
264265
virtual Result questionSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons,
265-
int defBtn = int(Button::NoButton), const Options& options = {}, const std::string& dialogTitle = "") = 0;
266+
int defBtn = int(Button::NoButton), const Options& options = {}, const std::string& dialogTitle = {}) = 0;
266267

267268
Result questionSync(const std::string& contentTitle, const std::string& text, const Buttons& buttons,
268-
const Button& defBtn = Button::NoButton, const Options& options = {}, const std::string& dialogTitle = "")
269+
const Button& defBtn = Button::NoButton, const Options& options = {}, const std::string& dialogTitle = {})
269270
{
270271
return questionSync(contentTitle, Text(text), buttonDataList(buttons), (int)defBtn, options, dialogTitle);
271272
}
272273

273274
virtual Result infoSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
274-
int defBtn = int(Button::NoButton), const Options& options = {}, const std::string& dialogTitle = "") = 0;
275+
int defBtn = int(Button::NoButton), const Options& options = {}, const std::string& dialogTitle = {}) = 0;
275276

276277
Result infoSync(const std::string& contentTitle, const std::string& text, const Buttons& buttons,
277-
const Button& defBtn = Button::NoButton, const Options& options = {}, const std::string& dialogTitle = "")
278+
const Button& defBtn = Button::NoButton, const Options& options = {}, const std::string& dialogTitle = {})
278279
{
279280
return infoSync(contentTitle, Text(text), buttonDataList(buttons), (int)defBtn, options, dialogTitle);
280281
}
281282

282283
virtual Result warningSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
283284
int defBtn = int(Button::NoButton), const Options& options = { WithIcon },
284-
const std::string& dialogTitle = "") = 0;
285+
const std::string& dialogTitle = {}) = 0;
285286

286287
Result warningSync(const std::string& contentTitle, const std::string& text, const Buttons& buttons,
287-
const Button& defBtn = Button::NoButton, const Options& options = { WithIcon }, const std::string& dialogTitle = "")
288+
const Button& defBtn = Button::NoButton, const Options& options = { WithIcon }, const std::string& dialogTitle = {})
288289
{
289290
return warningSync(contentTitle, Text(text), buttonDataList(buttons), (int)defBtn, options, dialogTitle);
290291
}
291292

292293
virtual Result errorSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
293294
int defBtn = int(Button::NoButton), const Options& options = { WithIcon },
294-
const std::string& dialogTitle = "") = 0;
295+
const std::string& dialogTitle = {}) = 0;
295296

296297
Result errorSync(const std::string& contentTitle, const std::string& text, const Buttons& buttons,
297-
const Button& defBtn = Button::NoButton, const Options& options = { WithIcon }, const std::string& dialogTitle = "")
298+
const Button& defBtn = Button::NoButton, const Options& options = { WithIcon }, const std::string& dialogTitle = {})
298299
{
299300
return errorSync(contentTitle, Text(text), buttonDataList(buttons), (int)defBtn, options, dialogTitle);
300301
}
@@ -306,5 +307,3 @@ class IInteractive : MODULE_EXPORT_INTERFACE
306307
};
307308
DECLARE_OPERATORS_FOR_FLAGS(IInteractive::Options)
308309
}
309-
310-
#endif // MUSE_GLOBAL_IINTERACTIVE_H

src/framework/global/internal/interactive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ io::paths_t Interactive::selectMultipleDirectories(const std::string& title, con
411411
return io::pathsFromString(result.val.toString());
412412
}
413413

414-
async::Promise<Color> Interactive::selectColor(const Color& color, const std::string& title)
414+
async::Promise<Color> Interactive::selectColor(const Color& color, const std::string& title, bool allowAlpha)
415415
{
416-
return provider()->selectColor(color, title);
416+
return provider()->selectColor(color, title, allowAlpha);
417417
}
418418

419419
bool Interactive::isSelectColorOpened() const

src/framework/global/internal/interactive.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* You should have received a copy of the GNU General Public License
2020
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2121
*/
22-
#ifndef MUSE_GLOBAL_INTERACTIVE_H
23-
#define MUSE_GLOBAL_INTERACTIVE_H
22+
23+
#pragma once
2424

2525
#include "async/asyncable.h"
2626

@@ -91,7 +91,7 @@ class Interactive : public IInteractive, public Injectable, public async::Asynca
9191
io::paths_t selectMultipleDirectories(const std::string& title, const io::path_t& dir, const io::paths_t& selectedDirectories) override;
9292

9393
// color
94-
async::Promise<Color> selectColor(const Color& color = Color::WHITE, const std::string& title = "") override;
94+
async::Promise<Color> selectColor(const Color& color = Color::WHITE, const std::string& title = {}, bool allowAlpha = false) override;
9595
bool isSelectColorOpened() const override;
9696

9797
// custom
@@ -134,5 +134,3 @@ class Interactive : public IInteractive, public Injectable, public async::Asynca
134134
const ButtonDatas& buttons, int defBtn, const Options& options, const std::string& dialogTitle);
135135
};
136136
}
137-
138-
#endif // MUSE_GLOBAL_UIINTERACTIVE_H

src/framework/global/internal/platform/web/webinteractive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ io::paths_t WebInteractive::selectMultipleDirectories(const std::string& title,
254254
#endif
255255
}
256256

257-
muse::async::Promise<muse::Color> WebInteractive::selectColor(const muse::Color& color, const std::string& title)
257+
muse::async::Promise<muse::Color> WebInteractive::selectColor(const muse::Color& color, const std::string& title, bool allowAlpha)
258258
{
259-
return m_origin->selectColor(color, title);
259+
return m_origin->selectColor(color, title, allowAlpha);
260260
}
261261

262262
bool WebInteractive::isSelectColorOpened() const

src/framework/global/internal/platform/web/webinteractive.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,35 @@ class WebInteractive : public muse::IInteractive
3333

3434
// question
3535
Result questionSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons, int defBtn = int(Button::NoButton),
36-
const Options& options = {}, const std::string& dialogTitle = "") override;
36+
const Options& options = {}, const std::string& dialogTitle = {}) override;
3737

3838
muse::async::Promise<Result> question(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons,
3939
int defBtn = int(Button::NoButton), const Options& options = {},
40-
const std::string& dialogTitle = "") override;
40+
const std::string& dialogTitle = {}) override;
4141

4242
// info
4343
Result infoSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons, int defBtn = int(Button::NoButton),
44-
const Options& options = {}, const std::string& dialogTitle = "") override;
44+
const Options& options = {}, const std::string& dialogTitle = {}) override;
4545

4646
muse::async::Promise<Result> info(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
4747
int defBtn = int(Button::NoButton), const Options& options = {},
48-
const std::string& dialogTitle = "") override;
48+
const std::string& dialogTitle = {}) override;
4949

5050
// warning
5151
Result warningSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons, int defBtn = int(Button::NoButton),
52-
const Options& options = {}, const std::string& dialogTitle = "") override;
52+
const Options& options = {}, const std::string& dialogTitle = {}) override;
5353

5454
muse::async::Promise<Result> warning(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
5555
int defBtn = int(Button::NoButton), const Options& options = {},
56-
const std::string& dialogTitle = "") override;
56+
const std::string& dialogTitle = {}) override;
5757

5858
// error
5959
Result errorSync(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons, int defBtn = int(Button::NoButton),
60-
const Options& options = { WithIcon }, const std::string& dialogTitle = "") override;
60+
const Options& options = { WithIcon }, const std::string& dialogTitle = {}) override;
6161

6262
muse::async::Promise<Result> error(const std::string& contentTitle, const Text& text, const ButtonDatas& buttons = {},
6363
int defBtn = int(Button::NoButton), const Options& options = { WithIcon },
64-
const std::string& dialogTitle = "") override;
64+
const std::string& dialogTitle = {}) override;
6565

6666
// progress
6767
void showProgress(const std::string& title, muse::Progress progress) override;
@@ -81,7 +81,8 @@ class WebInteractive : public muse::IInteractive
8181
const muse::io::paths_t& selectedDirectories) override;
8282

8383
// color
84-
muse::async::Promise<muse::Color> selectColor(const muse::Color& color = muse::Color::WHITE, const std::string& title = "") override;
84+
muse::async::Promise<muse::Color> selectColor(const muse::Color& color = muse::Color::WHITE, const std::string& title = {},
85+
bool allowAlpha = false) override;
8586
bool isSelectColorOpened() const override;
8687

8788
// custom

src/framework/global/tests/mocks/interactivemock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class InteractiveMock : public IInteractive
6565
MOCK_METHOD(io::path_t, selectDirectory, (const std::string&, const io::path_t&), (override));
6666
MOCK_METHOD(io::paths_t, selectMultipleDirectories, (const std::string&, const io::path_t&, const io::paths_t&), (override));
6767

68-
MOCK_METHOD(async::Promise<Color>, selectColor, (const Color&, const std::string&), (override));
68+
MOCK_METHOD(async::Promise<Color>, selectColor, (const Color&, const std::string&, bool), (override));
6969
MOCK_METHOD(bool, isSelectColorOpened, (), (const, override));
7070

7171
MOCK_METHOD(RetVal<Val>, openSync, (const UriQuery&), (override));

0 commit comments

Comments
 (0)