File: DecodeHighlightingListView.cpp

package info (click to toggle)
wsjtx-improved 3.0.0%2B250924%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 86,260 kB
  • sloc: cpp: 105,882; f90: 60,117; python: 27,241; ansic: 13,372; fortran: 2,382; makefile: 197; sh: 135
file content (74 lines) | stat: -rwxr-xr-x 3,373 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "DecodeHighlightingListView.hpp"

#include <QAction>
#include <QColorDialog>

#include "models/DecodeHighlightingModel.hpp"
#include "MessageBox.hpp"

#include "moc_DecodeHighlightingListView.cpp"

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 ();
}