32 #include <QStringList>
35 #include <QVBoxLayout>
37 #include <QApplication>
38 #include <QDesktopWidget>
42 using namespace LeechCraft::Util;
46 : QTreeWidget (parent)
49 setWindowTitle (tr (
"Tags selector"));
50 setWindowFlags (Qt::Tool | Qt::WindowStaysOnTopHint);
51 setRootIsDecorated (
false);
52 setUniformRowHeights (
true);
54 QRect avail = QApplication::desktop ()->availableGeometry (
this);
55 setMinimumHeight (avail.height () / 3 * 2);
58 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
60 SLOT (buttonToggled ()));
62 QAction *all =
new QAction (tr (
"Select all"),
this);
64 SIGNAL (triggered ()),
68 QAction *none =
new QAction (tr (
"Select none"),
this);
70 SIGNAL (triggered ()),
77 setContextMenuPolicy (Qt::ActionsContextMenu);
82 setHeaderLabel (caption);
89 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
91 SLOT (buttonToggled ()));
96 QList<QTreeWidgetItem*> items;
97 for (
auto i = mytags.begin (), end = mytags.end (); i != end; ++i)
102 auto item =
new QTreeWidgetItem (QStringList (*i));
103 item->setCheckState (0, Qt::Unchecked);
104 item->setData (0,
RoleTag, *i);
107 addTopLevelItems (items);
109 setHeaderLabel (Caption_);
112 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
114 SLOT (buttonToggled ()));
123 for (
int i = 0, size = topLevelItemCount ();
126 QTreeWidgetItem *item = topLevelItem (i);
127 if (item->checkState (0) == Qt::Checked)
128 tags += item->data (0,
RoleTag).toString ();
137 for (
int i = 0; i < topLevelItemCount (); ++i)
139 Qt::CheckState state =
140 tags.contains (topLevelItem (i)->data (0,
RoleTag).toString ()) ?
143 topLevelItem (i)->setCheckState (0, state);
145 blockSignals (
false);
160 QWidget::moveEvent (e);
161 QPoint pos = e->pos ();
162 QRect avail = QApplication::desktop ()->availableGeometry (
this);
164 if (pos.x () + width () > avail.width ())
165 dx = width () + pos.x () - avail.width ();
166 if (pos.y () + height () > avail.height () &&
167 height () < avail.height ())
168 dy = height () + pos.y () - avail.height ();
171 move (pos - QPoint (dx, dy));
177 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
179 SLOT (buttonToggled ()));
183 for (
int i = 0, size = topLevelItemCount (); i < size; ++i)
185 QTreeWidgetItem *item = topLevelItem (i);
186 item->setCheckState (0, Qt::Checked);
187 tags += item->data (0,
RoleTag).toString ();
191 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
193 SLOT (buttonToggled ()));
201 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
203 SLOT (buttonToggled ()));
205 for (
int i = 0; i < topLevelItemCount (); ++i)
206 topLevelItem (i)->setCheckState (0, Qt::Unchecked);
209 SIGNAL (itemChanged (QTreeWidgetItem*,
int)),
211 SLOT (buttonToggled ()));
218 QStringList tags = text.split (Separator_, QString::SkipEmptyParts);
222 void CategorySelector::buttonToggled ()
void selectNone()
Deselects all variants.
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.
UTIL_API void SetSeparator(const QString &)
Sets the separator for the tags.
void lineTextChanged(const QString &newText)
Notifies CategorySelector about logical selection changes.
void setPossibleSelections(QStringList selections)
Sets possible selections.
QStringList GetSelections()
Gets selected items.
UTIL_API QString GetSeparator() const
Returns the separator for the tags.
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.
CategorySelector(QWidget *parent=0)
Constructor.