diff options
author | Thilo Cestonaro <thilo@cestona.ro> | 2011-04-20 13:11:46 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-05-07 07:22:32 (GMT) |
commit | d631201597042e79ecef187ac7fd795cd7cc0cc0 (patch) | |
tree | 0e4d19b3bd5c5ad49324e5310b8a5dc9ab74cb96 /Swift | |
parent | 5e677a5e82ca660bb1fe25333baf4822893cdf3d (diff) | |
download | swift-d631201597042e79ecef187ac7fd795cd7cc0cc0.zip swift-d631201597042e79ecef187ac7fd795cd7cc0cc0.tar.bz2 |
Remember splitter position in a MUC dialog.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Signed-off-by: Remko Tronçon <git@el-tramo.be>
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 30 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.h | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindowFactory.cpp | 25 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindowFactory.h | 3 |
4 files changed, 55 insertions, 11 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 6086c42..95aecb7 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -13,6 +13,7 @@ #include "MessageSnippet.h" #include "SystemMessageSnippet.h" #include "QtTextEdit.h" +#include "QtSettingsProvider.h" #include "QtScaledAvatarCache.h" #include "SwifTools/TabComplete.h" @@ -38,24 +39,25 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt theme_ = theme; isCorrection_ = false; updateTitleWithUnreadCount(); + QtSettingsProvider settings; QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this); layout->setContentsMargins(0,0,0,0); layout->setSpacing(2); - - QSplitter *logRosterSplitter = new QSplitter(this); - logRosterSplitter->setAutoFillBackground(true); - layout->addWidget(logRosterSplitter); + logRosterSplitter_ = new QSplitter(this); + logRosterSplitter_->setAutoFillBackground(true); + layout->addWidget(logRosterSplitter_); messageLog_ = new QtChatView(theme, this); - logRosterSplitter->addWidget(messageLog_); + logRosterSplitter_->addWidget(messageLog_); treeWidget_ = new QtTreeWidget(eventStream_); treeWidget_->setEditable(false); treeWidget_->hide(); - logRosterSplitter->addWidget(treeWidget_); - logRosterSplitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + logRosterSplitter_->addWidget(treeWidget_); + logRosterSplitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + connect(logRosterSplitter_, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int))); QWidget* midBar = new QWidget(this); layout->addWidget(midBar); @@ -89,7 +91,7 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt connect(input_, SIGNAL(returnPressed()), this, SLOT(returnPressed())); connect(input_, SIGNAL(textChanged()), this, SLOT(handleInputChanged())); setFocusProxy(input_); - logRosterSplitter->setFocusProxy(input_); + logRosterSplitter_->setFocusProxy(input_); midBar->setFocusProxy(input_); messageLog_->setFocusProxy(input_); connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(qAppFocusChanged(QWidget*, QWidget*))); @@ -154,6 +156,18 @@ void QtChatWindow::cancelCorrection() { correctingLabel_->hide(); } +QByteArray QtChatWindow::getSplitterState() { + return logRosterSplitter_->saveState(); +} + +void QtChatWindow::handleChangeSplitterState(QByteArray state) { + logRosterSplitter_->restoreState(state); +} + +void QtChatWindow::handleSplitterMoved(int, int) { + emit splitterMoved(); +} + void QtChatWindow::tabComplete() { if (!completer_) { return; diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index a95041e..cb87970 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -18,6 +18,7 @@ class QTextEdit; class QLineEdit; class QComboBox; class QLabel; +class QSplitter; namespace Swift { class QtChatView; @@ -57,9 +58,14 @@ namespace Swift { void replaceLastMessage(const std::string& message); void setAckState(const std::string& id, AckState state); void flash(); + QByteArray getSplitterState(); + + public slots: + void handleChangeSplitterState(QByteArray state); signals: void geometryChanged(); + void splitterMoved(); protected slots: void qAppFocusChanged(QWidget* old, QWidget* now); @@ -74,6 +80,7 @@ namespace Swift { void returnPressed(); void handleInputChanged(); void handleKeyPressEvent(QKeyEvent* event); + void handleSplitterMoved(int pos, int index); private: void updateTitleWithUnreadCount(); @@ -104,5 +111,6 @@ namespace Swift { UIEventStream* eventStream_; bool inputEnabled_; IDGenerator id_; + QSplitter *logRosterSplitter_; }; } diff --git a/Swift/QtUI/QtChatWindowFactory.cpp b/Swift/QtUI/QtChatWindowFactory.cpp index d146474..4943c0e 100644 --- a/Swift/QtUI/QtChatWindowFactory.cpp +++ b/Swift/QtUI/QtChatWindowFactory.cpp @@ -16,6 +16,10 @@ namespace Swift { + +static const QString SPLITTER_STATE = "mucSplitterState"; +static const QString CHAT_TABS_GEOMETRY = "chatTabsGeometry"; + QtChatWindowFactory::QtChatWindowFactory(QSplitter* splitter, QtSettingsProvider* settings, QtChatTabs* tabs, const QString& themePath) : themePath_(themePath) { settings_ = settings; tabs_ = tabs; @@ -23,7 +27,7 @@ QtChatWindowFactory::QtChatWindowFactory(QSplitter* splitter, QtSettingsProvider if (splitter) { splitter->addWidget(tabs_); } else if (tabs_) { - QVariant chatTabsGeometryVariant = settings_->getQSettings()->value("chatTabsGeometry"); + QVariant chatTabsGeometryVariant = settings_->getQSettings()->value(CHAT_TABS_GEOMETRY); if (chatTabsGeometryVariant.isValid()) { tabs_->restoreGeometry(chatTabsGeometryVariant.toByteArray()); } @@ -43,11 +47,20 @@ ChatWindow* QtChatWindowFactory::createChatWindow(const JID &contact,UIEventStre theme_ = new QtChatTheme(""); /* Use the inbuilt theme */ } } + QtChatWindow *chatWindow = new QtChatWindow(P2QSTRING(contact.toString()), theme_, eventStream); + connect(chatWindow, SIGNAL(splitterMoved()), this, SLOT(handleSplitterMoved())); + connect(this, SIGNAL(changeSplitterState(QByteArray)), chatWindow, SLOT(handleChangeSplitterState(QByteArray))); + + QVariant splitterState = settings_->getQSettings()->value(SPLITTER_STATE); + if(splitterState.isValid()) { + chatWindow->handleChangeSplitterState(splitterState.toByteArray()); + } + if (tabs_) { tabs_->addTab(chatWindow); } else { - QVariant chatGeometryVariant = settings_->getQSettings()->value("chatTabsGeometry"); + QVariant chatGeometryVariant = settings_->getQSettings()->value(CHAT_TABS_GEOMETRY); if (chatGeometryVariant.isValid()) { chatWindow->restoreGeometry(chatGeometryVariant.toByteArray()); } @@ -57,7 +70,13 @@ ChatWindow* QtChatWindowFactory::createChatWindow(const JID &contact,UIEventStre } void QtChatWindowFactory::handleWindowGeometryChanged() { - settings_->getQSettings()->setValue("chatTabsGeometry", qobject_cast<QWidget*>(sender())->saveGeometry()); + settings_->getQSettings()->setValue(CHAT_TABS_GEOMETRY, qobject_cast<QWidget*>(sender())->saveGeometry()); +} + +void QtChatWindowFactory::handleSplitterMoved() { + QByteArray splitterState = qobject_cast<QtChatWindow*>(sender())->getSplitterState(); + settings_->getQSettings()->setValue(SPLITTER_STATE, QVariant(splitterState)); + emit changeSplitterState(splitterState); } } diff --git a/Swift/QtUI/QtChatWindowFactory.h b/Swift/QtUI/QtChatWindowFactory.h index 0d47854..f3e8956 100644 --- a/Swift/QtUI/QtChatWindowFactory.h +++ b/Swift/QtUI/QtChatWindowFactory.h @@ -22,8 +22,11 @@ namespace Swift { QtChatWindowFactory(QSplitter* splitter, QtSettingsProvider* settings, QtChatTabs* tabs, const QString& themePath); ~QtChatWindowFactory(); ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream); + signals: + void changeSplitterState(QByteArray); private slots: void handleWindowGeometryChanged(); + void handleSplitterMoved(); private: QString themePath_; QtSettingsProvider* settings_; |