summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-03-29 16:02:10 (GMT)
committerTobias Markmann <tm@ayena.de>2017-04-04 09:30:27 (GMT)
commiteb84a2f12778572ca97bb7ff8749fd80e84b16d4 (patch)
treeb8c8e21e6d1d0fbf73a2a5e031d1e4cf912cec66 /Swift/QtUI/Trellis/QtDNDTabBar.cpp
parentad66cc53f7e7ce860aee5b71b871a0ae9f8d357d (diff)
downloadswift-eb84a2f12778572ca97bb7ff8749fd80e84b16d4.zip
swift-eb84a2f12778572ca97bb7ff8749fd80e84b16d4.tar.bz2
Remove superfluous duplicated variable in QtDNDTabBar code
Coverity raised this issue. Test-Information: Swift and unit tests still build on macOS 10.12.4. Drag and drop of tabs still work. Change-Id: I64bdb973da73a4f2b5ed514583c4f8740adc77b4
Diffstat (limited to 'Swift/QtUI/Trellis/QtDNDTabBar.cpp')
-rw-r--r--Swift/QtUI/Trellis/QtDNDTabBar.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/Swift/QtUI/Trellis/QtDNDTabBar.cpp b/Swift/QtUI/Trellis/QtDNDTabBar.cpp
index 9a6c436..3ae2124 100644
--- a/Swift/QtUI/Trellis/QtDNDTabBar.cpp
+++ b/Swift/QtUI/Trellis/QtDNDTabBar.cpp
@@ -1,32 +1,32 @@
/*
- * Copyright (c) 2014-2016 Isode Limited.
+ * Copyright (c) 2014-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/Trellis/QtDNDTabBar.h>
#include <cassert>
#include <QDrag>
#include <QDropEvent>
#include <QMimeData>
#include <QMouseEvent>
#include <QPainter>
#include <QTabWidget>
namespace Swift {
QtDNDTabBar::QtDNDTabBar(QWidget* parent) : QTabBar(parent) {
setAcceptDrops(true);
// detect the default tab bar height;
insertTab(0, "");
defaultTabHeight = QTabBar::sizeHint().height();
removeTab(0);
}
QtDNDTabBar::~QtDNDTabBar() {
}
@@ -43,75 +43,73 @@ QWidget* QtDNDTabBar::getDragWidget() const {
}
QSize QtDNDTabBar::sizeHint() const {
QSize hint = QTabBar::sizeHint();
if (hint.isEmpty()) {
hint = QSize(parentWidget()->width(), defaultTabHeight);
}
return hint;
}
QSize QtDNDTabBar::tabSizeHint(int index) const {
QSize tabSize = QTabBar::tabSizeHint(index);
#if defined(Q_OS_MAC)
// With multiple tabs having the same label in a QTabBar, the size hint computed by
// Qt on OS X is too small and it is elided even though there is enough horizontal
// space available. We work around this issue by adding the width of a letter to the
// size hint.
tabSize += QSize(QFontMetrics(font()).width("I"), 0);
#endif
return tabSize;
}
void QtDNDTabBar::dragEnterEvent(QDragEnterEvent* dragEnterEvent) {
QtDNDTabBar* sourceTabBar = dynamic_cast<QtDNDTabBar*>(dragEnterEvent->source());
if (sourceTabBar) {
dragEnterEvent->acceptProposedAction();
}
}
void QtDNDTabBar::dropEvent(QDropEvent* dropEvent) {
- QtDNDTabBar* sourceTabBar = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
+ auto sourceTabBar = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
if (sourceTabBar && dropEvent->mimeData() && dropEvent->mimeData()->data("action") == QByteArray("application/tab-detach")) {
- QtDNDTabBar* source = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
-
int targetTabIndex = tabAt(dropEvent->pos());
QRect rect = tabRect(targetTabIndex);
if (targetTabIndex >= 0 && (dropEvent->pos().x() - rect.left() - rect.width()/2 > 0)) {
targetTabIndex++;
}
- QWidget* tab = source->getDragWidget();
+ QWidget* tab = sourceTabBar->getDragWidget();
assert(tab);
QTabWidget* targetTabWidget = dynamic_cast<QTabWidget*>(parentWidget());
- QString tabText = source->getDragText();
+ QString tabText = sourceTabBar->getDragText();
/*
* When you add a widget to an empty QTabWidget, it's automatically made the current widget.
* Making the widget the current widget, widget->show() is called for the widget. Directly reacting
* to that event, and adding the widget again to the QTabWidget results in undefined behavior. For
* example the tab label is shown but the widget is neither has the old nor in the new QTabWidget as
* parent. Blocking signals on the QWidget to be added to a QTabWidget prevents this behavior.
*/
targetTabWidget->setUpdatesEnabled(false);
tab->blockSignals(true);
targetTabWidget->insertTab(targetTabIndex, tab, tabText);
dropEvent->acceptProposedAction();
tab->blockSignals(false);
targetTabWidget->setUpdatesEnabled(true);
onDropSucceeded();
}
}
bool QtDNDTabBar::event(QEvent* event) {
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
if (mouseEvent) {
QWidget* childAtPoint = window()->childAt(mapTo(window(), mouseEvent->pos()));
QtDNDTabBar* underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint);
if (!underMouse && childAtPoint) {
underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint->parent());
}
if (!underMouse && currentIndex() >= 0) {
// detach and drag
// stop move event