digiKam
ratingsearchutilities.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2008-03-14
7  * Description : User interface for searches
8  *
9  * Copyright (C) 2008-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_RATING_SEARCH_UTILITIES_H
25 #define DIGIKAM_RATING_SEARCH_UTILITIES_H
26 
27 // Qt includes
28 
29 #include <QAbstractListModel>
30 #include <QItemDelegate>
31 #include <QLabel>
32 #include <QComboBox>
33 
34 // Local includes
35 
36 #include "ratingwidget.h"
37 #include "comboboxutilities.h"
38 
39 class QTreeView;
40 class QVBoxLayout;
41 
42 namespace Digikam
43 {
44 
45 class RatingComboBoxModel;
46 class RatingComboBoxWidget;
47 
49 {
50  Q_OBJECT
51 
52 public:
53 
59  {
64  Null = -2,
65  NoRating = -1,
66  Rating0 = 0,
67  Rating1 = 1,
68  Rating2 = 2,
69  Rating3 = 3,
70  Rating4 = 4,
71  Rating5 = 5
72  };
73 
74 public:
75 
76  explicit RatingComboBox(QWidget* const parent = nullptr);
77 
79  RatingValue ratingValue() const;
80 
81 Q_SIGNALS:
82 
84 
85 protected Q_SLOTS:
86 
87  void currentValueChanged(const QModelIndex& current, const QModelIndex& previous);
88  void ratingWidgetChanged(int);
89 
90 protected:
91 
94 
95 private:
96 
97  bool m_syncing;
98 };
99 
100 // -- Internal classes ----------------------------------------------------------------
101 
103 {
104 public:
105 
107 
108  QRect drawStarPolygons(QPainter* p, int numberOfStars) const;
109 
110 protected:
111 
112  QPolygon m_starPolygon;
114 };
115 
116 // -------------------------------------------------------------------------
117 
119  public RatingStarDrawer
120 {
121  Q_OBJECT
122 
123 public:
124 
129  explicit RatingComboBoxWidget(QWidget* const parent = nullptr);
130 
133 
134 Q_SIGNALS:
135 
137 
138 protected Q_SLOTS:
139 
140  void slotRatingChanged(int);
141 
142 protected:
143 
144  void paintEvent(QPaintEvent*) override;
145 
146 protected:
147 
149 };
150 
151 // -------------------------------------------------------------------------
152 
153 class RatingComboBoxModel : public QAbstractListModel
154 {
155  Q_OBJECT
156 
157 public:
158 
160  {
161  RatingRole = Qt::UserRole
162  };
163 
164 public:
165 
166  explicit RatingComboBoxModel(QObject* const parent = nullptr);
167 
169 
170  int rowCount(const QModelIndex& parent) const override;
171  QVariant data(const QModelIndex& index, int role) const override;
172  QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const override;
173 
174 protected:
175 
177 
178 protected:
179 
181 };
182 
183 // -------------------------------------------------------------------------
184 
185 class RatingComboBoxDelegate : public QItemDelegate,
186  public RatingStarDrawer
187 {
188  Q_OBJECT
189 
190 public:
191 
192  explicit RatingComboBoxDelegate(QObject* const parent = nullptr);
193 
194  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
195  void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
196 
197 protected:
198 
199  void drawRating(QPainter* painter, const QRect& rect, int rating, bool selectable) const;
200 };
201 
202 } // namespace Digikam
203 
204 #endif // DIGIKAM_RATING_SEARCH_UTILITIES_H
Definition: comboboxutilities.h:130
Definition: ratingsearchutilities.h:187
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: ratingsearchutilities.cpp:87
RatingComboBoxDelegate(QObject *const parent=nullptr)
Definition: ratingsearchutilities.cpp:82
void drawRating(QPainter *painter, const QRect &rect, int rating, bool selectable) const
Definition: ratingsearchutilities.cpp:134
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: ratingsearchutilities.cpp:105
Definition: ratingsearchutilities.h:154
QList< RatingComboBox::RatingValue > m_entries
Definition: ratingsearchutilities.h:180
int rowCount(const QModelIndex &parent) const override
Definition: ratingsearchutilities.cpp:174
RatingComboBoxModel(QObject *const parent=nullptr)
Definition: ratingsearchutilities.cpp:165
QModelIndex index(int row, int column=0, const QModelIndex &parent=QModelIndex()) const override
Definition: ratingsearchutilities.cpp:231
QVariant ratingValueToDisplay(RatingComboBox::RatingValue value) const
Definition: ratingsearchutilities.cpp:203
QModelIndex indexForRatingValue(RatingComboBox::RatingValue value) const
Definition: ratingsearchutilities.cpp:243
CustomRoles
Definition: ratingsearchutilities.h:160
@ RatingRole
Definition: ratingsearchutilities.h:161
QVariant data(const QModelIndex &index, int role) const override
Definition: ratingsearchutilities.cpp:184
Definition: ratingsearchutilities.h:120
void slotRatingChanged(int)
Definition: ratingsearchutilities.cpp:308
void ratingValueChanged(int value)
void setRatingValue(RatingComboBox::RatingValue value)
Definition: ratingsearchutilities.cpp:280
void paintEvent(QPaintEvent *) override
Definition: ratingsearchutilities.cpp:319
RatingComboBox::RatingValue ratingValue() const
Definition: ratingsearchutilities.cpp:275
RatingComboBox::RatingValue m_value
Definition: ratingsearchutilities.h:148
RatingComboBoxWidget(QWidget *const parent=nullptr)
Definition: ratingsearchutilities.cpp:257
Definition: ratingsearchutilities.h:49
void currentValueChanged(const QModelIndex &current, const QModelIndex &previous)
Definition: ratingsearchutilities.cpp:435
void setRatingValue(RatingValue value)
Definition: ratingsearchutilities.cpp:416
RatingValue
Definition: ratingsearchutilities.h:59
@ Rating5
Definition: ratingsearchutilities.h:71
@ Null
Definition: ratingsearchutilities.h:64
@ Rating1
Definition: ratingsearchutilities.h:67
@ NoRating
Definition: ratingsearchutilities.h:65
@ Rating4
Definition: ratingsearchutilities.h:70
@ Rating2
Definition: ratingsearchutilities.h:68
@ Rating0
Definition: ratingsearchutilities.h:66
@ Rating3
Definition: ratingsearchutilities.h:69
RatingValue ratingValue() const
Definition: ratingsearchutilities.cpp:430
RatingComboBoxModel * m_model
Definition: ratingsearchutilities.h:92
RatingComboBoxWidget * m_ratingWidget
Definition: ratingsearchutilities.h:93
void ratingWidgetChanged(int)
Definition: ratingsearchutilities.cpp:451
void ratingValueChanged(int value)
RatingComboBox(QWidget *const parent=nullptr)
Definition: ratingsearchutilities.cpp:387
Definition: ratingsearchutilities.h:103
RatingStarDrawer()
Definition: ratingsearchutilities.cpp:54
QSize m_starPolygonSize
Definition: ratingsearchutilities.h:113
QPolygon m_starPolygon
Definition: ratingsearchutilities.h:112
QRect drawStarPolygons(QPainter *p, int numberOfStars) const
Definition: ratingsearchutilities.cpp:60
Definition: ratingwidget.h:46
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43