32 #include <QStringList> 35 #include <QVBoxLayout> 37 #include <QApplication> 38 #include <QDesktopWidget> 41 #include "ui_categoryselector.h" 51 setWindowTitle (tr (
"Tags selector"));
52 setWindowFlags (Qt::Dialog | Qt::WindowStaysOnTopHint);
56 Ui_->Tree_->setRootIsDecorated (
false);
57 Ui_->Tree_->setUniformRowHeights (
true);
59 QRect avail = QApplication::desktop ()->availableGeometry (
this);
60 setMinimumHeight (avail.height () / 3 * 2);
63 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
65 SLOT (buttonToggled ()));
67 QAction *all =
new QAction (tr (
"Select all"),
this);
69 SIGNAL (triggered ()),
73 QAction *none =
new QAction (tr (
"Select none"),
this);
75 SIGNAL (triggered ()),
79 Ui_->Tree_->addAction (all);
80 Ui_->Tree_->addAction (none);
82 Ui_->Tree_->setContextMenuPolicy (Qt::ActionsContextMenu);
89 Ui_->Tree_->setHeaderLabel (caption);
95 disconnect (Ui_->Tree_,
96 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
98 SLOT (buttonToggled ()));
100 Ui_->Tree_->clear ();
106 for (
const auto& tag : mytags)
111 auto item =
new QTreeWidgetItem ({ tag });
112 item->setCheckState (0, Qt::Unchecked);
113 item->setData (0,
RoleTag, tag);
116 Ui_->Tree_->addTopLevelItems (items);
118 Ui_->Tree_->setHeaderLabel (Caption_);
121 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
123 SLOT (buttonToggled ()));
132 for (
int i = 0, size = Ui_->Tree_->topLevelItemCount (); i < size; ++i)
134 const auto item = Ui_->Tree_->topLevelItem (i);
135 if (item->checkState (0) == Qt::Checked)
136 tags += item->data (0,
RoleTag).toString ();
146 for (
int i = 0, size = Ui_->Tree_->topLevelItemCount (); i < size; ++i)
148 const auto item = Ui_->Tree_->topLevelItem (i);
149 if (item->checkState (0) == Qt::Checked)
159 for (
int i = 0; i < Ui_->Tree_->topLevelItemCount (); ++i)
161 const auto& tagVar = Ui_->Tree_->topLevelItem (i)->data (0,
RoleTag);
162 const auto state = tags.contains (tagVar.toString ()) ?
165 Ui_->Tree_->topLevelItem (i)->setCheckState (0, state);
167 blockSignals (
false);
185 Ui_->ButtonsBox_->setVisible (
false);
189 Ui_->ButtonsBox_->setVisible (
true);
192 Ui_->ButtonsBox_->setStandardButtons (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
193 Ui_->ButtonsBox_->setVisible (
true);
200 QWidget::moveEvent (e);
201 QPoint
pos = e->pos ();
202 QRect avail = QApplication::desktop ()->availableGeometry (
this);
204 if (
pos.x () + width () > avail.width ())
205 dx = width () +
pos.x () - avail.width ();
206 if (
pos.y () + height () > avail.height () &&
207 height () < avail.height ())
208 dy = height () +
pos.y () - avail.height ();
211 move (
pos - QPoint (dx, dy));
216 disconnect (Ui_->Tree_,
217 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
219 SLOT (buttonToggled ()));
223 for (
int i = 0, size = Ui_->Tree_->topLevelItemCount (); i < size; ++i)
225 const auto item = Ui_->Tree_->topLevelItem (i);
226 item->setCheckState (0, Qt::Checked);
227 tags += item->data (0,
RoleTag).toString ();
231 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
233 SLOT (buttonToggled ()));
240 disconnect (Ui_->Tree_,
241 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
243 SLOT (buttonToggled ()));
245 for (
int i = 0; i < Ui_->Tree_->topLevelItemCount (); ++i)
246 Ui_->Tree_->topLevelItem (i)->setCheckState (0, Qt::Unchecked);
249 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
251 SLOT (buttonToggled ()));
258 const auto& tags = text.split (Separator_, QString::SkipEmptyParts);
262 void CategorySelector::buttonToggled ()
void selectNone()
Deselects all variants.
QString GetSeparator() const
Returns the separator for the tags.
detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, boost::mpl::int_< Idx > > pos
void SetCaption(const QString &caption)
Sets the caption of this selector.
void SetSelections(const QStringList &subset)
Selects some of the items.
void selectAll()
Selects all variants.
void setPossibleSelections(QStringList selections, bool sort=true)
Sets possible selections.
void SetButtonsMode(ButtonsMode)
Sets the buttons mode.
void SetSeparator(const QString &)
Sets the separator for the tags.
QStringList GetSelections() const
Gets selected items.
void lineTextChanged(const QString &newText)
Notifies CategorySelector about logical selection changes.
virtual void moveEvent(QMoveEvent *)
Checks whether after the move event the selector won't be beoynd the screen. if it would...
void tagsSelectionChanged(const QStringList &newSelections)
Indicates that selections have changed.
QList< int > GetSelectedIndexes() const
Gets the indexes of the selected items.
CategorySelector(QWidget *parent=0)
Constructor.
The CategorySelector widget provides a way to select amongst a group of items.