diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/MainWindow.cpp | 16 | ||||
-rw-r--r-- | application/groupview/InstanceDelegate.cpp | 22 | ||||
-rw-r--r-- | application/groupview/InstanceDelegate.h | 15 |
3 files changed, 32 insertions, 21 deletions
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 595e0615..66e1f141 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -1091,10 +1091,12 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *ev) QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); switch (keyEvent->key()) { + /* case Qt::Key_Enter: case Qt::Key_Return: activateInstance(m_selectedInstance); return true; + */ case Qt::Key_Delete: on_actionDeleteInstance_triggered(); return true; @@ -1639,19 +1641,7 @@ void MainWindow::on_actionRenameInstance_triggered() { if (m_selectedInstance) { - bool ok = false; - QString name(m_selectedInstance->name()); - name = QInputDialog::getText(this, tr("Instance name"), tr("Enter a new instance name."), QLineEdit::Normal, name, &ok); - - name = name.trimmed(); - if (name.length() > 0) - { - if (ok && name.length()) - { - m_selectedInstance->setName(name); - ui->renameButton->setText(name); - } - } + view->edit(view->currentIndex()); } } diff --git a/application/groupview/InstanceDelegate.cpp b/application/groupview/InstanceDelegate.cpp index 42860aef..75ce6fc3 100644 --- a/application/groupview/InstanceDelegate.cpp +++ b/application/groupview/InstanceDelegate.cpp @@ -19,11 +19,13 @@ #include <QTextLayout> #include <QApplication> #include <QtMath> +#include <QDebug> #include "GroupView.h" #include "BaseInstance.h" #include "InstanceList.h" #include <xdgicon.h> +#include <QPlainTextEdit> // Origin: Qt static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height, @@ -165,8 +167,7 @@ static QSize viewItemTextSize(const QStyleOptionViewItem *option) textLayout.setTextOption(textOption); textLayout.setFont(option->font); textLayout.setText(option->text); - const int textMargin = - style->pixelMetric(QStyle::PM_FocusFrameHMargin, option, option->widget) + 1; + const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, option, option->widget) + 1; QRect bounds(0, 0, 100 - 2 * textMargin, 600); qreal height = 0, widthUsed = 0; viewItemTextLayout(textLayout, bounds.width(), height, widthUsed); @@ -331,8 +332,7 @@ QSize ListViewDelegate::sizeHint(const QStyleOptionViewItem &option, opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter; QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); - const int textMargin = - style->pixelMetric(QStyle::PM_FocusFrameHMargin, &option, opt.widget) + 1; + const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, &option, opt.widget) + 1; int height = 48 + textMargin * 2 + 5; // TODO: turn constants into variables QSize szz = viewItemTextSize(&opt); height += szz.height(); @@ -341,3 +341,17 @@ QSize ListViewDelegate::sizeHint(const QStyleOptionViewItem &option, return sz; } +void ListViewDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + const int iconSize = 48; + QRect textRect = option.rect; + textRect.adjust(0, iconSize + 5, 0, 0); + editor->setGeometry(textRect); +} + +QWidget * ListViewDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + auto *le = new QLineEdit(parent); + le->setFrame(false); + return le; +} diff --git a/application/groupview/InstanceDelegate.h b/application/groupview/InstanceDelegate.h index d0076e60..251ed875 100644 --- a/application/groupview/InstanceDelegate.h +++ b/application/groupview/InstanceDelegate.h @@ -20,11 +20,18 @@ class ListViewDelegate : public QStyledItemDelegate { + Q_OBJECT + public: explicit ListViewDelegate(QObject *parent = 0); + virtual ~ListViewDelegate() {} -protected: - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const override; + QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override; + /* + void setEditorData(QWidget * editor, const QModelIndex & index) const override; + void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; + */ }; |