summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/BlockListController.cpp34
-rw-r--r--Swift/Controllers/UIInterfaces/BlockListEditorWidget.h8
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.cpp103
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.h15
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.ui55
-rw-r--r--Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp20
6 files changed, 189 insertions, 46 deletions
diff --git a/Swift/Controllers/BlockListController.cpp b/Swift/Controllers/BlockListController.cpp
index d778883..9cd42f0 100644
--- a/Swift/Controllers/BlockListController.cpp
+++ b/Swift/Controllers/BlockListController.cpp
@@ -1,12 +1,18 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include <Swift/Controllers/BlockListController.h>
#include <boost/bind.hpp>
#include <Swiften/Client/ClientBlockListManager.h>
@@ -54,12 +60,13 @@ void BlockListController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
if (blockListEditorWidget_ == NULL) {
blockListEditorWidget_ = blockListEditorWidgetFactory_->createBlockListEditorWidget();
blockListEditorWidget_->onSetNewBlockList.connect(boost::bind(&BlockListController::handleSetNewBlockList, this, _1));
}
blockListBeforeEdit = blockListManager_->getBlockList()->getItems();
blockListEditorWidget_->setCurrentBlockList(blockListBeforeEdit);
+ blockListEditorWidget_->setError("");
blockListEditorWidget_->show();
return;
}
// handle block state change
boost::shared_ptr<RequestChangeBlockStateUIEvent> changeStateEvent = boost::dynamic_pointer_cast<RequestChangeBlockStateUIEvent>(rawEvent);
@@ -82,36 +89,50 @@ void BlockListController::handleBlockResponse(GenericRequest<BlockPayload>::ref
std::string errorMessage;
// FIXME: Handle reporting of list of JIDs in a translatable way.
errorMessage = str(format(QT_TRANSLATE_NOOP("", "Failed to block %1%.")) % jids.at(0).toString());
if (!error->getText().empty()) {
errorMessage = str(format(QT_TRANSLATE_NOOP("", "%1%: %2%.")) % errorMessage % error->getText());
}
- eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage));
+ if (blockListEditorWidget_ && originEditor) {
+ blockListEditorWidget_->setError(errorMessage);
+ blockListEditorWidget_->setBusy(false);
+ }
+ else {
+ eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage));
+ }
}
if (originEditor) {
remainingRequests_--;
- if (blockListEditorWidget_ && (remainingRequests_ == 0)) {
+ if (blockListEditorWidget_ && (remainingRequests_ == 0) && !error) {
blockListEditorWidget_->setBusy(false);
+ blockListEditorWidget_->hide();
}
}
}
void BlockListController::handleUnblockResponse(GenericRequest<UnblockPayload>::ref request, boost::shared_ptr<UnblockPayload>, ErrorPayload::ref error, const std::vector<JID>& jids, bool originEditor) {
if (error) {
std::string errorMessage;
// FIXME: Handle reporting of list of JIDs in a translatable way.
errorMessage = str(format(QT_TRANSLATE_NOOP("", "Failed to unblock %1%.")) % jids.at(0).toString());
if (!error->getText().empty()) {
errorMessage = str(format(QT_TRANSLATE_NOOP("", "%1%: %2%.")) % errorMessage % error->getText());
}
- eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage));
+ if (blockListEditorWidget_ && originEditor) {
+ blockListEditorWidget_->setError(errorMessage);
+ blockListEditorWidget_->setBusy(false);
+ }
+ else {
+ eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage));
+ }
}
if (originEditor) {
remainingRequests_--;
- if (blockListEditorWidget_ && (remainingRequests_ == 0)) {
+ if (blockListEditorWidget_ && (remainingRequests_ == 0) && !error) {
blockListEditorWidget_->setBusy(false);
+ blockListEditorWidget_->hide();
}
}
}
void BlockListController::handleSetNewBlockList(const std::vector<JID> &newBlockList) {
std::vector<JID> jidsToBlock;
@@ -128,15 +149,18 @@ void BlockListController::handleSetNewBlockList(const std::vector<JID> &newBlock
if (!jidsToUnblock.empty()) {
remainingRequests_++;
GenericRequest<UnblockPayload>::ref unblockRequest = blockListManager_->createUnblockJIDsRequest(jidsToUnblock);
unblockRequest->onResponse.connect(boost::bind(&BlockListController::handleUnblockResponse, this, unblockRequest, _1, _2, jidsToUnblock, true));
unblockRequest->send();
}
- if (!jidsToBlock.empty() || jidsToUnblock.empty()) {
+ if (!jidsToBlock.empty() || !jidsToUnblock.empty()) {
assert(blockListEditorWidget_);
blockListEditorWidget_->setBusy(true);
+ blockListEditorWidget_->setError("");
+ } else {
+ blockListEditorWidget_->hide();
}
}
void BlockListController::handleBlockListChanged() {
if (blockListEditorWidget_) {
std::vector<JID> jidsToBlock;
diff --git a/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h b/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h
index 60a1c11..f8a4c59 100644
--- a/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h
+++ b/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h
@@ -1,12 +1,18 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#pragma once
#include <vector>
#include <Swiften/JID/JID.h>
#include <Swiften/Base/boost_bsignals.h>
@@ -17,15 +23,17 @@ namespace Swift {
class BlockListEditorWidget {
public:
virtual ~BlockListEditorWidget() {}
virtual void show() = 0;
+ virtual void hide() = 0;
virtual void setCurrentBlockList(const std::vector<JID>& blockedJIDs) = 0;
virtual void setBusy(bool isBusy) = 0;
+ virtual void setError(const std::string&) = 0;
virtual std::vector<JID> getCurrentBlockList() const = 0;
boost::signal<void (const std::vector<JID>& /* blockedJID */)> onSetNewBlockList;
};
diff --git a/Swift/QtUI/QtBlockListEditorWindow.cpp b/Swift/QtUI/QtBlockListEditorWindow.cpp
index a759a3f..2484eb7 100644
--- a/Swift/QtUI/QtBlockListEditorWindow.cpp
+++ b/Swift/QtUI/QtBlockListEditorWindow.cpp
@@ -1,27 +1,33 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include <QtBlockListEditorWindow.h>
#include <ui_QtBlockListEditorWindow.h>
#include <boost/bind.hpp>
#include <QLineEdit>
#include <QMovie>
#include <QShortcut>
#include <QStyledItemDelegate>
#include <QValidator>
+#include <Swift/QtUI/QtSwiftUtil.h>
#include <Swift/QtUI/QtUtilities.h>
-#include <Swiften/Client/ClientBlockListManager.h>
#include <Swiften/Base/foreach.h>
-#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swiften/Client/ClientBlockListManager.h>
#include <Swiften/JID/JID.h>
namespace Swift {
class QtJIDValidator : public QValidator {
public:
@@ -63,99 +69,158 @@ class QtJIDValidatedItemDelegate : public QItemDelegate {
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
editor->setGeometry(option.rect);
}
};
-QtBlockListEditorWindow::QtBlockListEditorWindow() : QWidget(), ui(new Ui::QtBlockListEditorWindow) {
+QtBlockListEditorWindow::QtBlockListEditorWindow() : QWidget(), ui(new Ui::QtBlockListEditorWindow), removeItemDelegate(0), editItemDelegate(0) {
ui->setupUi(this);
+
+ freshBlockListTemplate = tr("Click to add contact");
+
new QShortcut(QKeySequence::Close, this, SLOT(close()));
ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
- itemDelegate = new QtRemovableItemDelegate(style());
+ removeItemDelegate = new QtRemovableItemDelegate(style());
+ editItemDelegate = new QtJIDValidatedItemDelegate(this);
connect(ui->savePushButton, SIGNAL(clicked()), SLOT(applyChanges()));
ui->blockListTreeWidget->setColumnCount(2);
ui->blockListTreeWidget->header()->setStretchLastSection(false);
- ui->blockListTreeWidget->header()->resizeSection(1, itemDelegate->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
+ ui->blockListTreeWidget->header()->resizeSection(1, removeItemDelegate->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
#if QT_VERSION >= 0x050000
ui->blockListTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
#else
ui->blockListTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
#endif
ui->blockListTreeWidget->setHeaderHidden(true);
ui->blockListTreeWidget->setRootIsDecorated(false);
- ui->blockListTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked);
- ui->blockListTreeWidget->setItemDelegateForColumn(0, new QtJIDValidatedItemDelegate(this));
- ui->blockListTreeWidget->setItemDelegateForColumn(1, itemDelegate);
+ ui->blockListTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed);
+ ui->blockListTreeWidget->setItemDelegateForColumn(0, editItemDelegate);
+ ui->blockListTreeWidget->setItemDelegateForColumn(1, removeItemDelegate);
connect(ui->blockListTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(handleItemChanged(QTreeWidgetItem*,int)));
+ ui->blockListTreeWidget->installEventFilter(this);
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->blockListTreeWidget->addTopLevelItem(item);
}
QtBlockListEditorWindow::~QtBlockListEditorWindow() {
}
void QtBlockListEditorWindow::show() {
- QWidget::show();
+ QWidget::showNormal();
QWidget::activateWindow();
+ QWidget::raise();
+}
+
+void QtBlockListEditorWindow::hide() {
+ QWidget::hide();
}
-void QtBlockListEditorWindow::handleItemChanged(QTreeWidgetItem *, int) {
+void QtBlockListEditorWindow::handleItemChanged(QTreeWidgetItem *item, int) {
+ // check whether changed item contains a valid JID and make it removable
+ if (item && item->text(0) != freshBlockListTemplate) {
+ item->setText(1, "");
+ }
+
+ // check for empty rows and add an empty one so the user can add items
bool hasEmptyRow = false;
- QList<QTreeWidgetItem*> rows = ui->blockListTreeWidget->findItems("", Qt::MatchFixedString);
- foreach(QTreeWidgetItem* row, rows) {
- if (row->text(0).isEmpty()) {
+ for( int i = 0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i ) {
+ QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
+ if (row->text(0) == freshBlockListTemplate) {
hasEmptyRow = true;
}
+ else if (row->text(0).isEmpty()) {
+ ui->blockListTreeWidget->removeItemWidget(row, 0);
+ }
}
if (!hasEmptyRow) {
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->blockListTreeWidget->addTopLevelItem(item);
}
+
+ if (!item) {
+ ui->blockListTreeWidget->setCurrentItem(ui->blockListTreeWidget->topLevelItem(0));
+ }
}
void QtBlockListEditorWindow::applyChanges() {
onSetNewBlockList(getCurrentBlockList());
}
-void Swift::QtBlockListEditorWindow::setCurrentBlockList(const std::vector<JID> &blockedJIDs) {
+void QtBlockListEditorWindow::setCurrentBlockList(const std::vector<JID> &blockedJIDs) {
ui->blockListTreeWidget->clear();
foreach(const JID& jid, blockedJIDs) {
QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(jid.toString())) << "");
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->blockListTreeWidget->addTopLevelItem(item);
}
handleItemChanged(0,0);
}
-void Swift::QtBlockListEditorWindow::setBusy(bool isBusy) {
+void QtBlockListEditorWindow::setBusy(bool isBusy) {
if (isBusy) {
ui->throbberLabel->movie()->start();
ui->throbberLabel->show();
+ ui->blockListTreeWidget->setEnabled(false);
+ ui->savePushButton->setEnabled(false);
} else {
ui->throbberLabel->movie()->stop();
ui->throbberLabel->hide();
+ ui->blockListTreeWidget->setEnabled(true);
+ ui->savePushButton->setEnabled(true);
+ }
+}
+
+void QtBlockListEditorWindow::setError(const std::string& error) {
+ if (!error.empty()) {
+ ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
+ }
+ else {
+ ui->errorLabel->setText("");
}
}
std::vector<JID> Swift::QtBlockListEditorWindow::getCurrentBlockList() const {
std::vector<JID> futureBlockedJIDs;
for(int i=0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i) {
QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
- if (!row->text(0).isEmpty()) {
- futureBlockedJIDs.push_back(JID(Q2PSTRING(row->text(0))));
+ JID jid = JID(Q2PSTRING(row->text(0)));
+ if (!jid.toString().empty() && jid.isValid()) {
+ futureBlockedJIDs.push_back(jid);
}
}
return futureBlockedJIDs;
}
+bool QtBlockListEditorWindow::eventFilter(QObject* target, QEvent* event) {
+ if (target == ui->blockListTreeWidget) {
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Backspace) {
+ // remove currently selected item
+ QTreeWidgetItem* currentItem = ui->blockListTreeWidget->currentItem();
+ if (currentItem->text(0) != freshBlockListTemplate) {
+ ui->blockListTreeWidget->takeTopLevelItem(ui->blockListTreeWidget->indexOfTopLevelItem(currentItem));
+ return true;
+ }
+ }
+ else if (keyEvent->key() == Qt::Key_Return) {
+ // open editor for return key d
+ ui->blockListTreeWidget->editItem(ui->blockListTreeWidget->currentItem(), 0);
+ return true;
+ }
+ }
+ }
+ return QWidget::eventFilter(target, event);
+}
+
}
diff --git a/Swift/QtUI/QtBlockListEditorWindow.h b/Swift/QtUI/QtBlockListEditorWindow.h
index 4b124a3..dd083fd 100644
--- a/Swift/QtUI/QtBlockListEditorWindow.h
+++ b/Swift/QtUI/QtBlockListEditorWindow.h
@@ -1,12 +1,18 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#pragma once
#include <Swift/Controllers/UIInterfaces/BlockListEditorWidget.h>
#include <Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h>
#include <QWidget>
@@ -15,28 +21,35 @@
namespace Ui {
class QtBlockListEditorWindow;
}
namespace Swift {
+class QtJIDValidatedItemDelegate;
+
class QtBlockListEditorWindow : public QWidget, public BlockListEditorWidget {
Q_OBJECT
public:
QtBlockListEditorWindow();
virtual ~QtBlockListEditorWindow();
virtual void show();
+ virtual void hide();
virtual void setCurrentBlockList(const std::vector<JID>& blockedJIDs);
virtual void setBusy(bool isBusy);
+ virtual void setError(const std::string& error);
virtual std::vector<JID> getCurrentBlockList() const;
+ virtual bool eventFilter(QObject* target, QEvent* event);
private slots:
void handleItemChanged(QTreeWidgetItem*, int);
void applyChanges();
private:
Ui::QtBlockListEditorWindow* ui;
- QtRemovableItemDelegate* itemDelegate;
+ QtRemovableItemDelegate* removeItemDelegate;
+ QtJIDValidatedItemDelegate* editItemDelegate;
+ QString freshBlockListTemplate;
};
}
diff --git a/Swift/QtUI/QtBlockListEditorWindow.ui b/Swift/QtUI/QtBlockListEditorWindow.ui
index f71bbae..a611890 100644
--- a/Swift/QtUI/QtBlockListEditorWindow.ui
+++ b/Swift/QtUI/QtBlockListEditorWindow.ui
@@ -3,26 +3,51 @@
<class>QtBlockListEditorWindow</class>
<widget class="QWidget" name="QtBlockListEditorWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>348</width>
+ <width>333</width>
<height>262</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit Block List</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>5</number>
</property>
- <property name="margin">
+ <property name="leftMargin">
<number>5</number>
</property>
+ <property name="topMargin">
+ <number>5</number>
+ </property>
+ <property name="rightMargin">
+ <number>5</number>
+ </property>
+ <property name="bottomMargin">
+ <number>5</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;The follwing list shows all contacts that you have currently blocked. You can add contacts to the list at the buttom of the list and remove contacts by clicking on the right column.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignJustify|Qt::AlignVCenter</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
<item>
<widget class="QTreeWidget" name="blockListTreeWidget">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
@@ -35,25 +60,12 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
<widget class="QLabel" name="errorLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
@@ -68,12 +80,25 @@
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
<item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
<widget class="QPushButton" name="savePushButton">
<property name="text">
<string>Save</string>
</property>
<property name="default">
<bool>true</bool>
diff --git a/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp
index 1cae00a..d50585c 100644
--- a/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp
@@ -1,48 +1,56 @@
/*
* Copyright (c) 2012 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include "QtRemovableItemDelegate.h"
#include <Swiften/Base/Platform.h>
#include <QEvent>
#include <QPainter>
namespace Swift {
QtRemovableItemDelegate::QtRemovableItemDelegate(const QStyle* style) : style(style) {
}
-void QtRemovableItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex&) const {
+void QtRemovableItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
QStyleOption opt;
opt.state = option.state;
opt.state |= QStyle::State_AutoRaise;
if (option.state.testFlag(QStyle::State_MouseOver)) {
opt.state |= QStyle::State_Raised;
}
opt.rect = option.rect;
painter->save();
painter->fillRect(option.rect, option.state & QStyle::State_Selected ? option.palette.highlight() : option.palette.base());
+ if (index.data().toString().isEmpty()) {
#ifdef SWIFTEN_PLATFORM_MACOSX
- // workaround for Qt not painting relative to the cell we're in, on OS X
- int height = style->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0);
- painter->translate(option.rect.x(), option.rect.y() + (option.rect.height() - height)/2);
+ // workaround for Qt not painting relative to the cell we're in, on OS X
+ int height = style->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0);
+ painter->translate(option.rect.x(), option.rect.y() + (option.rect.height() - height)/2);
#endif
- style->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, painter);
+ style->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, painter);
+ }
painter->restore();
}
QWidget* QtRemovableItemDelegate::createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const {
return NULL;
}
bool QtRemovableItemDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) {
- if (event->type() == QEvent::MouseButtonRelease) {
+ if (index.data().toString().isEmpty() && event->type() == QEvent::MouseButtonRelease) {
model->removeRow(index.row());
return true;
} else {
return QItemDelegate::editorEvent(event, model, option, index);
}
}