diff options
author | Joanna Hulboj <joanna.hulboj@isode.com> | 2017-01-12 11:10:23 (GMT) |
---|---|---|
committer | Joanna Hulboj <joanna.hulboj@isode.com> | 2017-01-18 10:39:02 (GMT) |
commit | fa068e62cbf70d93296de7887cbcfdda5d36d2b2 (patch) | |
tree | 8993c4d5bddb7446dcd675f522af73c519e3db44 /Swift/QtUI/QtChatTabs.cpp | |
parent | e649c54daa666c99d2f934b223acd0262c05e11a (diff) | |
download | swift-fa068e62cbf70d93296de7887cbcfdda5d36d2b2.zip swift-fa068e62cbf70d93296de7887cbcfdda5d36d2b2.tar.bz2 |
Set cursor position to the center of the screen to show layout window in the middle of the screen
Test-Information:
Tested with multiple screen setup.
Tested only on Windows.
From view menu choose "Change Layout", the layout window appears in the
middle of the screen.
Change-Id: Iab4ba64d54766426be39926773aa5b5bb628b9e9
Diffstat (limited to 'Swift/QtUI/QtChatTabs.cpp')
-rw-r--r-- | Swift/QtUI/QtChatTabs.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index 3241858..de9d2d2 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -1,51 +1,52 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/QtUI/QtChatTabs.h> #include <algorithm> #include <vector> #include <QAction> #include <QApplication> #include <QCloseEvent> #include <QCursor> #include <QDesktopWidget> #include <QLayout> #include <QMenu> #include <QTabBar> #include <QTabWidget> #include <QtGlobal> +#include <QWindow> #include <Swiften/Base/Log.h> #include <Swift/Controllers/ChatMessageSummarizer.h> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtTabWidget.h> #include <Swift/QtUI/QtTabbable.h> #include <Swift/QtUI/QtUISettingConstants.h> #include <Swift/QtUI/Trellis/QtDynamicGridLayout.h> #include <Swift/QtUI/Trellis/QtGridSelectionDialog.h> namespace Swift { QtChatTabs::QtChatTabs(bool singleWindow, SettingsProvider* settingsProvider, bool trellisMode) : QWidget(), singleWindow_(singleWindow), settingsProvider_(settingsProvider), trellisMode_(trellisMode), dynamicGrid_(nullptr), gridSelectionDialog_(nullptr) { #ifndef Q_OS_MAC setWindowIcon(QIcon(":/logo-chat-16.png")); #else setAttribute(Qt::WA_ShowWithoutActivating); #endif dynamicGrid_ = new QtDynamicGridLayout(this, trellisMode); connect(dynamicGrid_, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabCloseRequested(int))); connect(dynamicGrid_, SIGNAL(onCurrentIndexChanged(int)), this, SLOT(handleCurrentTabIndexChanged(int))); QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(0); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(dynamicGrid_); setLayout(layout); if (trellisMode) { @@ -345,63 +346,70 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) { case QtTabbable::WaitingActivity : tabTextColor = QColor(217, 20, 43); break; case QtTabbable::ImpendingActivity : tabTextColor = QColor(27, 171, 32); break; case QtTabbable::NoActivity : tabTextColor = QColor(); break; } tabWidget->tabBar()->setTabTextColor(tabIndex, tabTextColor); std::vector<std::pair<std::string, int> > unreads; for (int i = 0; i < dynamicGrid_->count(); i++) { QtTabbable* tab = qobject_cast<QtTabbable*>(dynamicGrid_->widget(i)); if (tab) { unreads.push_back(std::pair<std::string, int>(Q2PSTRING(tab->windowTitle()), tab->getCount())); } } std::string current(Q2PSTRING(qobject_cast<QtTabbable*>(dynamicGrid_->currentWidget())->windowTitle())); ChatMessageSummarizer summary; QString title = summary.getSummary(current, unreads).c_str(); setWindowTitle(title); emit onTitleChanged(title); } void QtChatTabs::flash() { #ifndef SWIFTEN_PLATFORM_MACOSX QApplication::alert(this, 0); #endif } void QtChatTabs::handleOpenLayoutChangeDialog() { disconnect(gridSelectionDialog_, SIGNAL(currentGridSizeChanged(QSize)), dynamicGrid_, SLOT(setDimensions(QSize))); gridSelectionDialog_->setCurrentGridSize(dynamicGrid_->getDimension()); - gridSelectionDialog_->move(QCursor::pos()); + + int screen = QApplication::desktop()->screenNumber(QCursor::pos()); + QPoint center = QApplication::desktop()->screenGeometry(screen).center(); + gridSelectionDialog_->move(center); + connect(gridSelectionDialog_, SIGNAL(currentGridSizeChanged(QSize)), dynamicGrid_, SLOT(setDimensions(QSize))); gridSelectionDialog_->show(); + + QPoint pos(gridSelectionDialog_->getFrameSize().width() / 2, gridSelectionDialog_->getFrameSize().height() / 2); + QCursor::setPos(gridSelectionDialog_->windowHandle()->screen(), gridSelectionDialog_->mapToGlobal(QPoint(gridSelectionDialog_->width(), gridSelectionDialog_->height()) - pos)); } void QtChatTabs::storeTabPositions() { // save size QByteArray gridSizeData; QDataStream dataStreamGridSize(&gridSizeData, QIODevice::ReadWrite); dataStreamGridSize << dynamicGrid_->getDimension(); settingsProvider_->storeSetting(QtUISettingConstants::TRELLIS_GRID_SIZE, Q2PSTRING(QString(gridSizeData.toBase64()))); // save positions QByteArray tabPositionsData; QDataStream dataStreamTabPositions(&tabPositionsData, QIODevice::ReadWrite); dynamicGrid_->updateTabPositions(); dataStreamTabPositions << dynamicGrid_->getTabPositions(); settingsProvider_->storeSetting(QtUISettingConstants::TRELLIS_GRID_POSITIONS, Q2PSTRING(QString(tabPositionsData.toBase64()))); } void QtChatTabs::resizeEvent(QResizeEvent*) { emit geometryChanged(); } void QtChatTabs::moveEvent(QMoveEvent*) { emit geometryChanged(); } void QtChatTabs::checkForFirstShow() { if (!isVisible()) { #ifndef Q_OS_MAC showMinimized(); #else |