Krita Source Code Documentation
Loading...
Searching...
No Matches
KisCategorizedListView Class Reference

#include <kis_categorized_list_view.h>

+ Inheritance diagram for KisCategorizedListView:

Signals

void lockAreaTriggered (const QModelIndex &index)
 
void rightClickedMenuDropSettingsTriggered ()
 
void rightClickedMenuSaveSettingsTriggered ()
 
void sigCategoryToggled (const QModelIndex &index, bool toggled)
 
void sigEntryChecked (const QModelIndex &index)
 

Public Member Functions

 KisCategorizedListView (QWidget *parent=0)
 
void setCompositeBoxControl (bool value)
 
void setModel (QAbstractItemModel *model) override
 
QSize sizeHint () const override
 
 ~KisCategorizedListView () override
 

Protected Slots

void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >()) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end) override
 
void rowsInserted (const QModelIndex &parent, int start, int end) override
 
void slotIndexChanged (const QModelIndex &index)
 
void slotScrollerStateChange (QScroller::State state)
 

Private Member Functions

void updateRows (int begin, int end)
 

Private Attributes

bool isCompositeBoxControl = false
 

Detailed Description

Definition at line 15 of file kis_categorized_list_view.h.

Constructor & Destructor Documentation

◆ KisCategorizedListView()

KisCategorizedListView::KisCategorizedListView ( QWidget * parent = 0)

Definition at line 19 of file kis_categorized_list_view.cpp.

19 :
20 QListView(parent)
21{
22 connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(slotIndexChanged(QModelIndex)));
23
24 // Because this widget has a darker background, the checkbox borders get hidden with default palette
25 // This palette update makes the checkboxes easier to see by starting with the text color
26 QPalette newPall = palette();
27 newPall.setColor(QPalette::Active, QPalette::Window, palette().text().color() );
28 setPalette(newPall);
29
30 {
31 QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(this);
32 if (scroller) {
33 connect(scroller, SIGNAL(stateChanged(QScroller::State)), this, SLOT(slotScrollerStateChange(QScroller::State)));
34 }
35 }
36}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotScrollerStateChange(QScroller::State state)
void slotIndexChanged(const QModelIndex &index)
KRITAWIDGETUTILS_EXPORT QScroller * createPreconfiguredScroller(QAbstractScrollArea *target)
rgba palette[MAX_PALETTE]
Definition palette.c:35

References connect(), KisKineticScroller::createPreconfiguredScroller(), palette, slotIndexChanged(), and slotScrollerStateChange().

◆ ~KisCategorizedListView()

KisCategorizedListView::~KisCategorizedListView ( )
override

Definition at line 38 of file kis_categorized_list_view.cpp.

39{
40}

Member Function Documentation

◆ dataChanged

void KisCategorizedListView::dataChanged ( const QModelIndex & topLeft,
const QModelIndex & bottomRight,
const QVector< int > & roles = QVector<int>() )
overrideprotectedslot

Definition at line 81 of file kis_categorized_list_view.cpp.

82{
83 QListView::dataChanged(topLeft, bottomRight);
84 updateRows(topLeft.row(), bottomRight.row()+1);
85
86 // check to see if the data changed was a check box
87 // if it is a checkbox tell the brush editor that the preset is now "dirty"
88 int i = 0;
89 for (QVector<int>::const_iterator iterator = roles.begin(); iterator != roles.end(); ++iterator) {
90
91 if (Qt::CheckStateRole == roles.at(i) ) {
92 int row = topLeft.row();
93 int column = topLeft.column();
94
95 Q_EMIT sigEntryChecked(model()->index(row, column));
96 } else if (__CategorizedListModelBase::ExpandCategoryRole == roles.at(i)) {
97 // logic to target the expand/contract menus if needed
98 }
99
100 i++;
101 }
102}
void sigEntryChecked(const QModelIndex &index)
void updateRows(int begin, int end)

References __CategorizedListModelBase::ExpandCategoryRole, sigEntryChecked(), and updateRows().

◆ lockAreaTriggered

void KisCategorizedListView::lockAreaTriggered ( const QModelIndex & index)
signal

◆ mousePressEvent

void KisCategorizedListView::mousePressEvent ( QMouseEvent * event)
overrideprotectedslot

Definition at line 117 of file kis_categorized_list_view.cpp.

118{
119 QListView::mousePressEvent(event);
120
121 QModelIndex index = QListView::indexAt(event->pos());
122
123
124 // hack: the custom compositeop combo box has issues with events being sent
125 // those widgets will run this extra code to help them know if a checkbox is clicked
127
128 if (index.isValid() && (event->pos().x() < 25) && (model()->flags(index) & Qt::ItemIsUserCheckable)) {
129 QListView::mousePressEvent(event);
130 QMouseEvent releaseEvent(QEvent::MouseButtonRelease,
131 event->pos(),
132 event->globalPos(),
133 event->button(),
134 event->button() | event->buttons(),
135 event->modifiers());
136
137 QListView::mouseReleaseEvent(&releaseEvent);
138 Q_EMIT sigEntryChecked(index);
139
140 return; // don't worry about running the 'right' click logic below. that is not relevant with composite ops
141 }
142 }
143
144
145
146 if (event->button() == Qt::RightButton){
147
148 QMenu menu(this);
149
150 if(index.data(__CategorizedListModelBase::isLockableRole).toBool() && index.isValid()) {
151
152 bool locked = index.data(__CategorizedListModelBase::isLockedRole).toBool();
153
154 QIcon icon = locked ? KisIconUtils::loadIcon("unlocked") : KisIconUtils::loadIcon("locked");
155
156 // Add an empty section so there's a bit more space before users accidentally press lock
157 // See https://bugs.kde.org/show_bug.cgi?id=447367
158 menu.addSection(" ");
159
160 QAction* action1 = menu.addAction(icon, locked ? i18n("Unlock (restore settings from preset)")
161 : i18n("Lock"));
162
163 connect(action1, SIGNAL(triggered()), this, SIGNAL(rightClickedMenuDropSettingsTriggered()));
164
165 if (locked){
166 QAction* action2 = menu.addAction(icon, i18n("Unlock (keep current settings)"));
167 connect(action2, SIGNAL(triggered()), this, SIGNAL(rightClickedMenuSaveSettingsTriggered()));
168 }
169 menu.exec(event->globalPos());
170 }
171 }
172}
void rightClickedMenuSaveSettingsTriggered()
void rightClickedMenuDropSettingsTriggered()
QIcon loadIcon(const QString &name)

References connect(), isCompositeBoxControl, __CategorizedListModelBase::isLockableRole, __CategorizedListModelBase::isLockedRole, KisIconUtils::loadIcon(), rightClickedMenuDropSettingsTriggered(), rightClickedMenuSaveSettingsTriggered(), and sigEntryChecked().

◆ mouseReleaseEvent

void KisCategorizedListView::mouseReleaseEvent ( QMouseEvent * event)
overrideprotectedslot

Definition at line 174 of file kis_categorized_list_view.cpp.

175{
176 QListView::mouseReleaseEvent(event);
177}

◆ rightClickedMenuDropSettingsTriggered

void KisCategorizedListView::rightClickedMenuDropSettingsTriggered ( )
signal

◆ rightClickedMenuSaveSettingsTriggered

void KisCategorizedListView::rightClickedMenuSaveSettingsTriggered ( )
signal

◆ rowsAboutToBeRemoved

void KisCategorizedListView::rowsAboutToBeRemoved ( const QModelIndex & parent,
int start,
int end )
overrideprotectedslot

Definition at line 111 of file kis_categorized_list_view.cpp.

112{
113 QListView::rowsAboutToBeRemoved(parent, start, end);
114 model()->sort(0);
115}

◆ rowsInserted

void KisCategorizedListView::rowsInserted ( const QModelIndex & parent,
int start,
int end )
overrideprotectedslot

Definition at line 104 of file kis_categorized_list_view.cpp.

105{
106 QListView::rowsInserted(parent, start, end);
107 updateRows(0, model()->rowCount());
108 model()->sort(0);
109}

References updateRows().

◆ setCompositeBoxControl()

void KisCategorizedListView::setCompositeBoxControl ( bool value)

Definition at line 57 of file kis_categorized_list_view.cpp.

58{
60}
float value(const T *src, size_t ch)

References isCompositeBoxControl, and value().

◆ setModel()

void KisCategorizedListView::setModel ( QAbstractItemModel * model)
override

Definition at line 42 of file kis_categorized_list_view.cpp.

43{
44 QListView::setModel(model);
45 updateRows(0, model->rowCount());
46 model->sort(0);
47}

References updateRows().

◆ sigCategoryToggled

void KisCategorizedListView::sigCategoryToggled ( const QModelIndex & index,
bool toggled )
signal

◆ sigEntryChecked

void KisCategorizedListView::sigEntryChecked ( const QModelIndex & index)
signal

◆ sizeHint()

QSize KisCategorizedListView::sizeHint ( ) const
override

Definition at line 49 of file kis_categorized_list_view.cpp.

50{
51 const QSize sh = QListView::sizeHint();
52 const int width = sizeHintForColumn(0);
53
54 return QSize(width, sh.height());
55}

◆ slotIndexChanged

void KisCategorizedListView::slotIndexChanged ( const QModelIndex & index)
protectedslot

Definition at line 72 of file kis_categorized_list_view.cpp.

73{
74 if(model()->data(index, __CategorizedListModelBase::IsHeaderRole).toBool()) {
75 bool expanded = model()->data(index, __CategorizedListModelBase::ExpandCategoryRole).toBool();
76 model()->setData(index, !expanded, __CategorizedListModelBase::ExpandCategoryRole);
77 Q_EMIT sigCategoryToggled(index, !expanded);
78 }
79}
void sigCategoryToggled(const QModelIndex &index, bool toggled)

References __CategorizedListModelBase::ExpandCategoryRole, __CategorizedListModelBase::IsHeaderRole, and sigCategoryToggled().

◆ slotScrollerStateChange

void KisCategorizedListView::slotScrollerStateChange ( QScroller::State state)
protectedslot

Definition at line 179 of file kis_categorized_list_view.cpp.

180{
182}
KRITAWIDGETUTILS_EXPORT void updateCursor(QWidget *source, QScroller::State state)

References KisKineticScroller::updateCursor().

◆ updateRows()

void KisCategorizedListView::updateRows ( int begin,
int end )
private

Definition at line 62 of file kis_categorized_list_view.cpp.

63{
64 for(; begin!=end; ++begin) {
65 QModelIndex index = model()->index(begin, 0);
66 bool isHeader = model()->data(index, __CategorizedListModelBase::IsHeaderRole).toBool();
67 bool expanded = model()->data(index, __CategorizedListModelBase::ExpandCategoryRole).toBool();
68 setRowHidden(begin, !expanded && !isHeader);
69 }
70}

References __CategorizedListModelBase::ExpandCategoryRole, and __CategorizedListModelBase::IsHeaderRole.

Member Data Documentation

◆ isCompositeBoxControl

bool KisCategorizedListView::isCompositeBoxControl = false
private

Definition at line 44 of file kis_categorized_list_view.h.


The documentation for this class was generated from the following files: