summaryrefslogtreecommitdiff
path: root/widgets/DecodeHighlightingListView.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2018-12-19 23:01:50 +0100
committerChristoph Berg <myon@debian.org>2018-12-19 23:01:50 +0100
commit5c60c77adff9a54fd5f94f9915b22ccd8c4c5a3b (patch)
tree410fa358a5f73260a579b4d669730f319a4d2609 /widgets/DecodeHighlightingListView.cpp
parent6c82050de806dcdafaed0077400a6c3396a4a159 (diff)
parente0737c56c1e384e05064a0c6e1ac46979371041b (diff)
Update upstream source from tag 'upstream/2.0.0+repack'
Update to upstream version '2.0.0+repack' with Debian dir 55dbb3a6a7eb189e187dd79f732623ca0b56116d
Diffstat (limited to 'widgets/DecodeHighlightingListView.cpp')
-rw-r--r--widgets/DecodeHighlightingListView.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/widgets/DecodeHighlightingListView.cpp b/widgets/DecodeHighlightingListView.cpp
new file mode 100644
index 00000000..cc5ea5d2
--- /dev/null
+++ b/widgets/DecodeHighlightingListView.cpp
@@ -0,0 +1,72 @@
+#include "DecodeHighlightingListView.hpp"
+
+#include <QAction>
+#include <QColorDialog>
+
+#include "models/DecodeHighlightingModel.hpp"
+#include "MessageBox.hpp"
+
+DecodeHighlightingListView::DecodeHighlightingListView (QWidget * parent)
+ : QListView {parent}
+{
+ auto * fg_colour_action = new QAction {tr ("&Foreground color ..."), this};
+ addAction (fg_colour_action);
+ connect (fg_colour_action, &QAction::triggered, [this] (bool /*checked*/) {
+ auto const& index = currentIndex ();
+ auto colour = QColorDialog::getColor (model ()->data (index, Qt::ForegroundRole).value<QBrush> ().color ()
+ , this
+ , tr ("Choose %1 Foreground Color")
+ .arg (model ()->data (index).toString ()));
+ if (colour.isValid ())
+ {
+ model ()->setData (index, QBrush {colour}, Qt::ForegroundRole);
+ }
+ });
+
+ auto * unset_fg_colour_action = new QAction {tr ("&Unset foreground color"), this};
+ addAction (unset_fg_colour_action);
+ connect (unset_fg_colour_action, &QAction::triggered, [this] (bool /*checked*/) {
+ model ()->setData (currentIndex (), QBrush {}, Qt::ForegroundRole);
+ });
+
+ auto * bg_colour_action = new QAction {tr ("&Background color ..."), this};
+ addAction (bg_colour_action);
+ connect (bg_colour_action, &QAction::triggered, [this] (bool /*checked*/) {
+ auto const& index = currentIndex ();
+ auto colour = QColorDialog::getColor (model ()->data (index, Qt::BackgroundRole).value<QBrush> ().color ()
+ , this
+ , tr ("Choose %1 Background Color")
+ .arg (model ()->data (index).toString ()));
+ if (colour.isValid ())
+ {
+ model ()->setData (index, QBrush {colour}, Qt::BackgroundRole);
+ }
+ });
+
+ auto * unset_bg_colour_action = new QAction {tr ("U&nset background color"), this};
+ addAction (unset_bg_colour_action);
+ connect (unset_bg_colour_action, &QAction::triggered, [this] (bool /*checked*/) {
+ model ()->setData (currentIndex (), QBrush {}, Qt::BackgroundRole);
+ });
+
+ auto * defaults_action = new QAction {tr ("&Reset this item to defaults"), this};
+ addAction (defaults_action);
+ connect (defaults_action, &QAction::triggered, [this] (bool /*checked*/) {
+ auto const& index = currentIndex ();
+ model ()->setData (index, model ()->data (index, DecodeHighlightingModel::EnabledDefaultRole).toBool () ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
+ model ()->setData (index, model ()->data (index, DecodeHighlightingModel::ForegroundDefaultRole), Qt::ForegroundRole);
+ model ()->setData (index, model ()->data (index, DecodeHighlightingModel::BackgroundDefaultRole), Qt::BackgroundRole);
+ });
+}
+
+QSize DecodeHighlightingListView::sizeHint () const
+{
+ auto item_height = sizeHintForRow (0);
+ if (item_height >= 0)
+ {
+ // set the height hint to exactly the space required for all the
+ // items
+ return {width (), (model ()->rowCount () * (item_height + 2 * spacing ())) + 2 * frameWidth ()};
+ }
+ return QListView::sizeHint ();
+}