27 #include <QApplication> 29 #include <QPushButton> 30 #include <QMessageBox> 31 #include <QInputDialog> 35 #include <ui_klfstylemanager.h> 44 return Qt::ItemIsDropEnabled;
45 return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
50 return data(index(row), Qt::DisplayRole).toString();
55 setData(index(row), newname, Qt::DisplayRole);
61 return Qt::CopyAction;
67 types <<
"application/x-klf-stylename";
76 if (indexes.size() > 1 || indexes.size() <= 0) {
81 QDataStream stream(&encodedData, QIODevice::WriteOnly);
83 mimeData->
setData(
"application/x-klf-stylename", encodedData);
90 if (action == Qt::IgnoreAction)
96 if (!mdata->
hasFormat(
"application/x-klf-stylename"))
105 QByteArray encodedData = mdata->
data(
"application/x-klf-stylename");
106 QDataStream stream(&encodedData, QIODevice::ReadOnly);
116 fprintf(stderr,
"WARNING: Ignoring drop of style named `%s' which was not already in list!\n",
117 newItem.toLocal8Bit().constData());
141 u =
new Ui::KLFStyleManager;
143 setObjectName(
"KLFStyleManager");
148 _drag_init_pos =
QPoint(-1,-1);
151 mActionsPopup =
new QMenu(
this);
159 u->btnActions->setMenu(mActionsPopup);
162 u->lstStyles->setModel(mStyleListModel);
170 connect(u->btnClose, SIGNAL(clicked()),
this, SLOT(
hide()));
172 u->lstStyles->installEventFilter(
this);
175 connect(mStyleListModel, SIGNAL(internalMoveCompleted(
int,
int)),
177 connect(u->lstStyles->selectionModel(),
189 u->retranslateUi(
this);
191 actPopupDelete->setText(tr(
"Delete Style"));
192 actPopupMoveUp->setText(tr(
"Move up"));
193 actPopupMoveDown->setText(tr(
"Move down"));
194 actPopupRename->setText(tr(
"Rename style"));
203 int curidx = currentRow();
206 actPopupDelete->setEnabled(
true);
207 actPopupRename->setEnabled(
true);
208 actPopupMoveUp->setEnabled(curidx > 0);
209 actPopupMoveDown->setEnabled(curidx < mStyleListModel->rowCount()-1);
211 actPopupDelete->setEnabled(
false);
212 actPopupRename->setEnabled(
false);
213 actPopupMoveUp->setEnabled(
false);
214 actPopupMoveDown->setEnabled(
false);
220 mActionsPopup->
exec(u->lstStyles->mapToGlobal(pos));
224 int KLFStyleManager::currentRow()
226 QModelIndexList sel = u->lstStyles->selectionModel()->selectedRows();
229 if (sel.size() >= 2) {
230 qWarning(
"Multiple style names selected! Expected Single Selection Policy!\n");
238 int r = currentRow();
242 if (
QMessageBox::question(
this, tr(
"Erase style?"), tr(
"Are you sure you want to erase selected style?"),
243 QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes ) {
254 int r = currentRow();
259 _styptr->
at(r).name);
262 _styptr->operator[](r).name = newname;
272 int r = currentRow();
273 if ( r < 1 || r >= mStyleListModel->
rowCount() )
287 int r = currentRow();
288 if ( r < 0 || r > mStyleListModel->
rowCount() - 1 )
304 _styptr->
insert(newpos, sty);
307 u->lstStyles->selectionModel()->select(i, QItemSelectionModel::ClearAndSelect);
308 u->lstStyles->setCurrentIndex(i);
317 for (
int i = 0; i < _styptr->
size(); ++i) {
318 list << _styptr->
at(i).name;
void refreshActionsEnabledState()
data(const QString &mimeType)
Qt::DropActions supportedDropActions() const
QStringList mimeTypes() const
void showActionsContextMenu(const QPoint &pos)
QMimeData * mimeData(const QModelIndexList &indexes) const
setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
rowCount(const QModelIndex &parent=QModelIndex()
removeRows(int row, int count, const QModelIndex &parent=QModelIndex()
data(const QModelIndex &index, int role)
question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void retranslateUi(bool alsoBaseUi=true)
insertRows(int row, int count, const QModelIndex &parent=QModelIndex()
virtual void setStyleName(int row, const QString &newname)
virtual QString styleName(int row) const
#define KLF_DEBUG_TIME_BLOCK(msg)
getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode=QLineEdit::Normal, const QString &text=QString()
void slotModelMoveCompleted(int previouspos, int newpos)
void internalMoveCompleted(int prevrow, int newrow)
insert(int i, const T &value)
setData(const QString &mimeType, const QByteArray &data)
KLFStyleManager(KLFStyleList *ptr, QWidget *parent)
setStringList(const QStringList &strings)