diff options
| author | Tobias Markmann <tm@ayena.de> | 2015-05-31 09:25:48 (GMT) |
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2015-05-31 18:10:20 (GMT) |
| commit | 5b851c72510ef88feb059455033915588fa6fb8c (patch) | |
| tree | 8f02dba6cefa1d564f4ea29c74a2504e4c7a181a | |
| parent | c62f1fc1006474809597a75ed920795da38e4113 (diff) | |
| download | swift-5b851c72510ef88feb059455033915588fa6fb8c.zip swift-5b851c72510ef88feb059455033915588fa6fb8c.tar.bz2 | |
Open profile windows in their ideal size so everything is readable
Test-Information:
Tested on OS X 10.9.5 with Qt 5.4.1 and Windows 8 with Qt 5.3.2 and
KUbuntu 14.04 with Qt 5.4.1.
Change-Id: Ia6cf54baad3020d05be94c6159aa623f7a619816
| -rw-r--r-- | Swift/QtUI/QtProfileWindow.cpp | 55 | ||||
| -rw-r--r-- | Swift/QtUI/QtProfileWindow.h | 11 |
2 files changed, 41 insertions, 25 deletions
diff --git a/Swift/QtUI/QtProfileWindow.cpp b/Swift/QtUI/QtProfileWindow.cpp index 31a530f..71d4281 100644 --- a/Swift/QtUI/QtProfileWindow.cpp +++ b/Swift/QtUI/QtProfileWindow.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2011-2014 Isode Limited. | 2 | * Copyright (c) 2011-2015 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -10,13 +10,14 @@ | |||
| 10 | * See Documentation/Licenses/BSD-simplified.txt for more information. | 10 | * See Documentation/Licenses/BSD-simplified.txt for more information. |
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | #include "QtProfileWindow.h" | 13 | #include <Swift/QtUI/QtProfileWindow.h> |
| 14 | #include "ui_QtProfileWindow.h" | 14 | #include <Swift/QtUI/ui_QtProfileWindow.h> |
| 15 | 15 | ||
| 16 | #include <QCloseEvent> | 16 | #include <QCloseEvent> |
| 17 | #include <QMovie> | 17 | #include <QMovie> |
| 18 | #include <QShortcut> | 18 | #include <QShortcut> |
| 19 | #include <QTextDocument> | 19 | #include <QTextDocument> |
| 20 | #include <QTimer> | ||
| 20 | 21 | ||
| 21 | #include <Swift/QtUI/QtSwiftUtil.h> | 22 | #include <Swift/QtUI/QtSwiftUtil.h> |
| 22 | #include <Swift/QtUI/QtUtilities.h> | 23 | #include <Swift/QtUI/QtUtilities.h> |
| @@ -39,6 +40,10 @@ QtProfileWindow::QtProfileWindow() : | |||
| 39 | connect(ui->savePushButton, SIGNAL(clicked()), SLOT(handleSave())); | 40 | connect(ui->savePushButton, SIGNAL(clicked()), SLOT(handleSave())); |
| 40 | setEditable(false); | 41 | setEditable(false); |
| 41 | setAttribute(Qt::WA_DeleteOnClose); | 42 | setAttribute(Qt::WA_DeleteOnClose); |
| 43 | setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); | ||
| 44 | |||
| 45 | adjustSizeTimer.setSingleShot(true); | ||
| 46 | connect(&adjustSizeTimer, SIGNAL(timeout()), SLOT(handleAdjustSizeTimeout())); | ||
| 42 | } | 47 | } |
| 43 | 48 | ||
| 44 | QtProfileWindow::~QtProfileWindow() { | 49 | QtProfileWindow::~QtProfileWindow() { |
| @@ -59,7 +64,6 @@ void QtProfileWindow::setVCard(VCard::ref vcard) { | |||
| 59 | ui->vcard->setVisible(true); | 64 | ui->vcard->setVisible(true); |
| 60 | ui->emptyLabel->setVisible(false); | 65 | ui->emptyLabel->setVisible(false); |
| 61 | } | 66 | } |
| 62 | |||
| 63 | updateWindowSize(); | 67 | updateWindowSize(); |
| 64 | } | 68 | } |
| 65 | 69 | ||
| @@ -74,6 +78,7 @@ void QtProfileWindow::setEditable(bool b) { | |||
| 74 | ui->savePushButton->setVisible(b); | 78 | ui->savePushButton->setVisible(b); |
| 75 | ui->vcard->setEditable(b); | 79 | ui->vcard->setEditable(b); |
| 76 | updateTitle(); | 80 | updateTitle(); |
| 81 | updateWindowSize(); | ||
| 77 | } | 82 | } |
| 78 | 83 | ||
| 79 | void QtProfileWindow::setProcessing(bool processing) { | 84 | void QtProfileWindow::setProcessing(bool processing) { |
| @@ -89,8 +94,6 @@ void QtProfileWindow::setProcessing(bool processing) { | |||
| 89 | ui->statusLabel->setVisible(false); | 94 | ui->statusLabel->setVisible(false); |
| 90 | ui->vcard->setVisible(true); | 95 | ui->vcard->setVisible(true); |
| 91 | } | 96 | } |
| 92 | |||
| 93 | updateWindowSize(); | ||
| 94 | } | 97 | } |
| 95 | 98 | ||
| 96 | void QtProfileWindow::setError(const std::string& error) { | 99 | void QtProfileWindow::setError(const std::string& error) { |
| @@ -112,6 +115,10 @@ void QtProfileWindow::hide() { | |||
| 112 | QWidget::hide(); | 115 | QWidget::hide(); |
| 113 | } | 116 | } |
| 114 | 117 | ||
| 118 | QSize QtProfileWindow::sizeHint() const { | ||
| 119 | return QWidget::sizeHint() + QSize(0, 15); | ||
| 120 | } | ||
| 121 | |||
| 115 | void QtProfileWindow::updateTitle() { | 122 | void QtProfileWindow::updateTitle() { |
| 116 | QString jidString; | 123 | QString jidString; |
| 117 | if (jid.isValid()) { | 124 | if (jid.isValid()) { |
| @@ -126,22 +133,14 @@ void QtProfileWindow::updateTitle() { | |||
| 126 | } | 133 | } |
| 127 | 134 | ||
| 128 | void QtProfileWindow::updateWindowSize() { | 135 | void QtProfileWindow::updateWindowSize() { |
| 129 | int width = 0; | 136 | // Delay resizing to the end of the event loop, because Qt calculates the correct layout asynchronously. |
| 130 | int height = 0; | 137 | // Qt will post LayoutRequests for widgets on the event loop on show and widgets will recaluclate their |
| 131 | 138 | // layout as they process these events. | |
| 132 | QSize size = ui->statusLabel->size(); | 139 | // We use the complete and correct size hint from the freshly calculated layout by delaying execution of |
| 133 | width = std::max(width, size.width()); | 140 | // the resize code to the end of Qt's event loop. |
| 134 | height = std::max(height, size.height() * 3); | 141 | if (!adjustSizeTimer.isActive()) { |
| 135 | 142 | adjustSizeTimer.start(0); | |
| 136 | size = ui->emptyLabel->size(); | 143 | } |
| 137 | width = std::max(width, size.width()); | ||
| 138 | height = std::max(height, size.height() * 3); | ||
| 139 | |||
| 140 | size = ui->vcard->size(); | ||
| 141 | width = std::max(width, size.width()); | ||
| 142 | height = std::max(height, size.height()); | ||
| 143 | |||
| 144 | resize(width, height); | ||
| 145 | } | 144 | } |
| 146 | 145 | ||
| 147 | void QtProfileWindow::closeEvent(QCloseEvent* event) { | 146 | void QtProfileWindow::closeEvent(QCloseEvent* event) { |
| @@ -153,4 +152,16 @@ void QtProfileWindow::handleSave() { | |||
| 153 | onVCardChangeRequest(ui->vcard->getVCard()); | 152 | onVCardChangeRequest(ui->vcard->getVCard()); |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 155 | void QtProfileWindow::handleAdjustSizeTimeout() { | ||
| 156 | // Force recaluclation of all layout geometry in children widgets. | ||
| 157 | // This is required on Windows to have the correct size even on first show. | ||
| 158 | QList<QWidget *> children = findChildren<QWidget*>(); | ||
| 159 | foreach(QWidget* child, children) { | ||
| 160 | child->updateGeometry(); | ||
| 161 | } | ||
| 162 | |||
| 163 | updateGeometry(); | ||
| 164 | adjustSize(); | ||
| 165 | } | ||
| 166 | |||
| 156 | } | 167 | } |
diff --git a/Swift/QtUI/QtProfileWindow.h b/Swift/QtUI/QtProfileWindow.h index d1eed99..0821444 100644 --- a/Swift/QtUI/QtProfileWindow.h +++ b/Swift/QtUI/QtProfileWindow.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2011 Isode Limited. | 2 | * Copyright (c) 2011-2015 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -12,12 +12,13 @@ | |||
| 12 | 12 | ||
| 13 | #pragma once | 13 | #pragma once |
| 14 | 14 | ||
| 15 | #include <QTimer> | ||
| 16 | #include <QWidget> | ||
| 17 | |||
| 15 | #include <Swiften/JID/JID.h> | 18 | #include <Swiften/JID/JID.h> |
| 16 | 19 | ||
| 17 | #include <Swift/Controllers/UIInterfaces/ProfileWindow.h> | 20 | #include <Swift/Controllers/UIInterfaces/ProfileWindow.h> |
| 18 | 21 | ||
| 19 | #include <QWidget> | ||
| 20 | |||
| 21 | namespace Ui { | 22 | namespace Ui { |
| 22 | class QtProfileWindow; | 23 | class QtProfileWindow; |
| 23 | } | 24 | } |
| @@ -42,6 +43,8 @@ class QtProfileWindow : public QWidget, public ProfileWindow { | |||
| 42 | virtual void show(); | 43 | virtual void show(); |
| 43 | virtual void hide(); | 44 | virtual void hide(); |
| 44 | 45 | ||
| 46 | virtual QSize sizeHint() const; | ||
| 47 | |||
| 45 | private: | 48 | private: |
| 46 | void updateTitle(); | 49 | void updateTitle(); |
| 47 | void updateWindowSize(); | 50 | void updateWindowSize(); |
| @@ -49,10 +52,12 @@ class QtProfileWindow : public QWidget, public ProfileWindow { | |||
| 49 | 52 | ||
| 50 | private slots: | 53 | private slots: |
| 51 | void handleSave(); | 54 | void handleSave(); |
| 55 | void handleAdjustSizeTimeout(); | ||
| 52 | 56 | ||
| 53 | private: | 57 | private: |
| 54 | Ui::QtProfileWindow* ui; | 58 | Ui::QtProfileWindow* ui; |
| 55 | JID jid; | 59 | JID jid; |
| 60 | QTimer adjustSizeTimer; | ||
| 56 | }; | 61 | }; |
| 57 | 62 | ||
| 58 | } | 63 | } |
Swift