diff options
27 files changed, 183 insertions, 65 deletions
diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp index 29dba62..bcd1585 100644 --- a/Swift/QtUI/ChatList/ChatListDelegate.cpp +++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp @@ -16,7 +16,7 @@ namespace Swift { -ChatListDelegate::ChatListDelegate() { +ChatListDelegate::ChatListDelegate(bool compact) : compact_(compact) { groupDelegate_ = new GroupItemDelegate(); } @@ -24,13 +24,17 @@ ChatListDelegate::~ChatListDelegate() { delete groupDelegate_; } +void ChatListDelegate::setCompact(bool compact) { + compact_ = compact; +} + QSize ChatListDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer()); if (item && dynamic_cast<ChatListMUCItem*>(item)) { return mucSizeHint(option, index); } else if (item && dynamic_cast<ChatListRecentItem*>(item)) { - return common_.contactSizeHint(option, index); + return common_.contactSizeHint(option, index, compact_); } else if (item && dynamic_cast<ChatListGroupItem*>(item)) { return groupDelegate_->sizeHint(option, index); @@ -109,7 +113,7 @@ void ChatListDelegate::paintRecent(QPainter* painter, const QStyleOptionViewItem QString name = item->data(Qt::DisplayRole).toString(); //qDebug() << "Avatar for " << name << " = " << avatarPath; QString statusText = item->data(ChatListRecentItem::DetailTextRole).toString(); - common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, item->getChat().unreadCount); + common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, item->getChat().unreadCount, compact_); } } diff --git a/Swift/QtUI/ChatList/ChatListDelegate.h b/Swift/QtUI/ChatList/ChatListDelegate.h index a898df4..5ac45ce 100644 --- a/Swift/QtUI/ChatList/ChatListDelegate.h +++ b/Swift/QtUI/ChatList/ChatListDelegate.h @@ -15,16 +15,19 @@ namespace Swift { class ChatListRecentItem; class ChatListDelegate : public QStyledItemDelegate { public: - ChatListDelegate(); + ChatListDelegate(bool compact); ~ChatListDelegate(); QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + public slots: + void setCompact(bool compact); private: void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, ChatListMUCItem* item) const; void paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const; QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const; QSize recentSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const; + bool compact_; DelegateCommons common_; GroupItemDelegate* groupDelegate_; }; diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index e5c63f6..8de5720 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -9,24 +9,26 @@ #include <QMenu> #include <QContextMenuEvent> -#include "Swift/QtUI/ChatList/ChatListMUCItem.h" -#include "Swift/QtUI/ChatList/ChatListRecentItem.h" -#include "Swift/QtUI/QtAddBookmarkWindow.h" -#include "Swift/QtUI/QtEditBookmarkWindow.h" -#include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" -#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" -#include "Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h" -#include "Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h" -#include "Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h" +#include <Swift/QtUI/ChatList/ChatListMUCItem.h> +#include <Swift/QtUI/ChatList/ChatListRecentItem.h> +#include <Swift/QtUI/QtAddBookmarkWindow.h> +#include <Swift/QtUI/QtEditBookmarkWindow.h> +#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> +#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> +#include <Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h> +#include <Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h> +#include <Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h> +#include <Swift/QtUI/QtUIPreferences.h> namespace Swift { -QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, QWidget* parent) : QTreeView(parent) { +QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, QtUIPreferences* uiPreferences, QWidget* parent) : QTreeView(parent) { eventStream_ = uiEventStream; + uiPreferences_ = uiPreferences; bookmarksEnabled_ = false; model_ = new ChatListModel(); setModel(model_); - delegate_ = new ChatListDelegate(); + delegate_ = new ChatListDelegate(uiPreferences_->getCompactRosters()); setItemDelegate(delegate_); setHeaderHidden(true); #ifdef SWIFT_PLATFORM_MACOSX @@ -39,6 +41,7 @@ QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, QWidget* parent setupContextMenus(); connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&))); connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&))); + connect(uiPreferences_, SIGNAL(onCompactRostersChanged(bool)), this, SLOT(handleCompactRostersToggled(bool))); } QtChatListWindow::~QtChatListWindow() { @@ -48,6 +51,11 @@ QtChatListWindow::~QtChatListWindow() { delete emptyMenu_; } +void QtChatListWindow::handleCompactRostersToggled(bool compact) { + delegate_->setCompact(compact); + repaint(); +} + void QtChatListWindow::setBookmarksEnabled(bool enabled) { bookmarksEnabled_ = enabled; } diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h index 8775c3e..af37015 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.h +++ b/Swift/QtUI/ChatList/QtChatListWindow.h @@ -14,11 +14,11 @@ #include "Swift/QtUI/ChatList/ChatListDelegate.h" namespace Swift { - + class QtUIPreferences; class QtChatListWindow : public QTreeView, public ChatListWindow { Q_OBJECT public: - QtChatListWindow(UIEventStream *uiEventStream, QWidget* parent = NULL); + QtChatListWindow(UIEventStream *uiEventStream, QtUIPreferences* uiPreferences, QWidget* parent = NULL); virtual ~QtChatListWindow(); void addMUCBookmark(const MUCBookmark& bookmark); void removeMUCBookmark(const MUCBookmark& bookmark); @@ -35,6 +35,7 @@ namespace Swift { void handleEditBookmark(); void handleRemoveBookmark(); void handleClicked(const QModelIndex& index); + void handleCompactRostersToggled(bool); protected: void contextMenuEvent(QContextMenuEvent* event); @@ -48,6 +49,7 @@ namespace Swift { QMenu* mucMenu_; QMenu* emptyMenu_; ChatListItem* contextMenuItem_; + QtUIPreferences* uiPreferences_; }; } diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 8270175..f0f268d 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -45,11 +45,13 @@ #include <QPushButton> #include <QFileDialog> #include <QMenu> +#include <Swift/QtUI/QtUIPreferences.h> #include <QDebug> namespace Swift { -QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream) : QtTabbable(), contact_(contact), previousMessageWasSelf_(false), previousMessageWasSystem_(false), previousMessageWasPresence_(false), previousMessageWasFileTransfer_(false), eventStream_(eventStream) { +QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream, QtUIPreferences* uiPreferences) : QtTabbable(), contact_(contact), previousMessageWasSelf_(false), previousMessageWasSystem_(false), previousMessageWasPresence_(false), previousMessageWasFileTransfer_(false), eventStream_(eventStream) { + uiPreferences_ = uiPreferences; unreadCount_ = 0; idCounter_ = 0; inputEnabled_ = true; @@ -108,7 +110,7 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt messageLog_ = new QtChatView(theme, this); logRosterSplitter_->addWidget(messageLog_); - treeWidget_ = new QtOccupantListWidget(eventStream_, this); + treeWidget_ = new QtOccupantListWidget(eventStream_, uiPreferences_, this); treeWidget_->hide(); logRosterSplitter_->addWidget(treeWidget_); logRosterSplitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 0c64f02..233f2bc 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -32,10 +32,12 @@ namespace Swift { class QtTextEdit; class UIEventStream; class QtFileTransferJSBridge; + class QtUIPreferences; + class QtChatWindow : public QtTabbable, public ChatWindow { Q_OBJECT public: - QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream); + QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream, QtUIPreferences* uiPreferences); ~QtChatWindow(); std::string addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time); std::string addAction(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time); @@ -156,5 +158,6 @@ namespace Swift { QPointer<QtMUCConfigurationWindow> mucConfigurationWindow_; QPointer<QtAffiliationEditor> affiliationEditor_; int idCounter_; + QtUIPreferences* uiPreferences_; }; } diff --git a/Swift/QtUI/QtChatWindowFactory.cpp b/Swift/QtUI/QtChatWindowFactory.cpp index 4943c0e..b860dae 100644 --- a/Swift/QtUI/QtChatWindowFactory.cpp +++ b/Swift/QtUI/QtChatWindowFactory.cpp @@ -20,9 +20,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) { +QtChatWindowFactory::QtChatWindowFactory(QSplitter* splitter, QtSettingsProvider* settings, QtChatTabs* tabs, const QString& themePath, QtUIPreferences* uiPreferences) : themePath_(themePath) { settings_ = settings; tabs_ = tabs; + uiPreferences_ = uiPreferences; theme_ = NULL; if (splitter) { splitter->addWidget(tabs_); @@ -48,7 +49,7 @@ ChatWindow* QtChatWindowFactory::createChatWindow(const JID &contact,UIEventStre } } - QtChatWindow *chatWindow = new QtChatWindow(P2QSTRING(contact.toString()), theme_, eventStream); + QtChatWindow *chatWindow = new QtChatWindow(P2QSTRING(contact.toString()), theme_, eventStream, uiPreferences_); connect(chatWindow, SIGNAL(splitterMoved()), this, SLOT(handleSplitterMoved())); connect(this, SIGNAL(changeSplitterState(QByteArray)), chatWindow, SLOT(handleChangeSplitterState(QByteArray))); diff --git a/Swift/QtUI/QtChatWindowFactory.h b/Swift/QtUI/QtChatWindowFactory.h index f3e8956..f664c43 100644 --- a/Swift/QtUI/QtChatWindowFactory.h +++ b/Swift/QtUI/QtChatWindowFactory.h @@ -16,10 +16,11 @@ namespace Swift { class QtChatTabs; class QtChatTheme; class UIEventStream; + class QtUIPreferences; class QtChatWindowFactory : public QObject, public ChatWindowFactory { Q_OBJECT public: - QtChatWindowFactory(QSplitter* splitter, QtSettingsProvider* settings, QtChatTabs* tabs, const QString& themePath); + QtChatWindowFactory(QSplitter* splitter, QtSettingsProvider* settings, QtChatTabs* tabs, const QString& themePath, QtUIPreferences* uiPreferences); ~QtChatWindowFactory(); ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream); signals: @@ -32,6 +33,7 @@ namespace Swift { QtSettingsProvider* settings_; QtChatTabs* tabs_; QtChatTheme* theme_; + QtUIPreferences* uiPreferences_; }; } diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 9d35435..a4ce98e 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -24,6 +24,7 @@ #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtTabWidget.h> #include <Swift/QtUI/QtSettingsProvider.h> +#include <Swift/QtUI/QtUIPreferences.h> #include <Roster/QtRosterWidget.h> #include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h> @@ -37,8 +38,9 @@ namespace Swift { #define CURRENT_ROSTER_TAB "current_roster_tab" -QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventStream) : QWidget(), MainWindow(false) { +QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventStream, QtUIPreferences* uiPreferences) : QWidget(), MainWindow(false) { uiEventStream_ = uiEventStream; + uiPreferences_ = uiPreferences; settings_ = settings; setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this); @@ -62,7 +64,7 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS contactTabLayout->setSpacing(0); contactTabLayout->setContentsMargins(0, 0, 0, 0); - treeWidget_ = new QtRosterWidget(uiEventStream_, this); + treeWidget_ = new QtRosterWidget(uiEventStream_, uiPreferences_, this); contactTabLayout->addWidget(treeWidget_); tabs_->addTab(contactsTabWidget_, tr("&Contacts")); @@ -70,7 +72,7 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS eventWindow_ = new QtEventWindow(uiEventStream_); connect(eventWindow_, SIGNAL(onNewEventCountUpdated(int)), this, SLOT(handleEventCountUpdated(int))); - chatListWindow_ = new QtChatListWindow(uiEventStream_); + chatListWindow_ = new QtChatListWindow(uiEventStream_, uiPreferences_); connect(chatListWindow_, SIGNAL(onCountUpdated(int)), this, SLOT(handleChatCountUpdated(int))); tabs_->addTab(chatListWindow_, tr("C&hats")); @@ -90,6 +92,12 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS connect(showOfflineAction_, SIGNAL(toggled(bool)), SLOT(handleShowOfflineToggled(bool))); viewMenu->addAction(showOfflineAction_); + //QAction* compactRosterAction_ = new QAction(tr("&Compact Roster"), this); + //compactRosterAction_->setCheckable(true); + //compactRosterAction_->setChecked(false); + //connect(compactRosterAction_, SIGNAL(toggled(bool)), uiPreferences_, SLOT(setCompactRosters(bool))); + //viewMenu->addAction(compactRosterAction_); + QMenu* actionsMenu = new QMenu(tr("&Actions"), this); menus_.push_back(actionsMenu); QAction* editProfileAction = new QAction(tr("Edit &Profile"), this); diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h index 321fa2d..afcb57c 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -30,11 +30,12 @@ namespace Swift { class UIEventStream; class QtTabWidget; class QtSettingsProvider; + class QtUIPreferences; class QtMainWindow : public QWidget, public MainWindow { Q_OBJECT public: - QtMainWindow(QtSettingsProvider*, UIEventStream* eventStream); + QtMainWindow(QtSettingsProvider*, UIEventStream* eventStream, QtUIPreferences* uiPreferences); virtual ~QtMainWindow(); std::vector<QMenu*> getMenus() {return menus_;} void setMyNick(const std::string& name); @@ -81,5 +82,6 @@ namespace Swift { bool lastOfflineState_; std::vector<DiscoItems::Item> serverAdHocCommands_; QList<QAction*> serverAdHocCommandActions_; + QtUIPreferences* uiPreferences_; }; } diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index 7f11b5c..f706deb 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -113,7 +113,7 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa applicationPathProvider_ = new PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME); storagesFactory_ = new FileStoragesFactory(applicationPathProvider_->getDataDir()); certificateStorageFactory_ = new CertificateFileStorageFactory(applicationPathProvider_->getDataDir(), tlsFactories_.getCertificateFactory()); - chatWindowFactory_ = new QtChatWindowFactory(splitter_, settings_, tabs_, ""); + chatWindowFactory_ = new QtChatWindowFactory(splitter_, settings_, tabs_, "", &uiPreferences_); soundPlayer_ = new QtSoundPlayer(applicationPathProvider_); // Ugly, because the dock depends on the tray, but the temporary @@ -154,7 +154,7 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa // Don't add the first tray (see note above) systemTrays_.push_back(new QtSystemTray()); } - QtUIFactory* uiFactory = new QtUIFactory(settings_, tabs_, splitter_, systemTrays_[i], chatWindowFactory_, startMinimized, eagleMode); + QtUIFactory* uiFactory = new QtUIFactory(settings_, tabs_, splitter_, systemTrays_[i], chatWindowFactory_, startMinimized, eagleMode, &uiPreferences_); uiFactories_.push_back(uiFactory); MainController* mainController = new MainController( &clientMainThreadCaller_, diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index 7f33475..c808fa0 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -23,6 +23,7 @@ #endif #include "SwifTools/Idle/PlatformIdleQuerier.h" #include "SwifTools/Idle/ActualIdleDetector.h" +#include <Swift/QtUI/QtUIPreferences.h> namespace po = boost::program_options; @@ -75,6 +76,7 @@ namespace Swift { Notifier* notifier_; PlatformIdleQuerier idleQuerier_; ActualIdleDetector idleDetector_; + QtUIPreferences uiPreferences_; #if defined(SWIFTEN_PLATFORM_MACOSX) CocoaApplication cocoaApplication_; #endif diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp index 5f55795..8a026f2 100644 --- a/Swift/QtUI/QtUIFactory.cpp +++ b/Swift/QtUI/QtUIFactory.cpp @@ -30,7 +30,7 @@ namespace Swift { -QtUIFactory::QtUIFactory(QtSettingsProvider* settings, QtChatTabs* tabs, QSplitter* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, bool startMinimized, bool eagleMode) : settings(settings), tabs(tabs), netbookSplitter(netbookSplitter), systemTray(systemTray), chatWindowFactory(chatWindowFactory), lastMainWindow(NULL), loginWindow(NULL), startMinimized(startMinimized), eagleMode(eagleMode) { +QtUIFactory::QtUIFactory(QtSettingsProvider* settings, QtChatTabs* tabs, QSplitter* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, bool startMinimized, bool eagleMode, QtUIPreferences* uiPreferences) : settings(settings), tabs(tabs), netbookSplitter(netbookSplitter), systemTray(systemTray), chatWindowFactory(chatWindowFactory), lastMainWindow(NULL), loginWindow(NULL), startMinimized(startMinimized), eagleMode(eagleMode), uiPreferences(uiPreferences) { chatFontSize = settings->getIntSetting(CHATWINDOW_FONT_SIZE, 0); } @@ -55,7 +55,7 @@ FileTransferListWidget* QtUIFactory::createFileTransferListWidget() { } MainWindow* QtUIFactory::createMainWindow(UIEventStream* eventStream) { - lastMainWindow = new QtMainWindow(settings, eventStream); + lastMainWindow = new QtMainWindow(settings, eventStream, uiPreferences); return lastMainWindow; } diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h index 319613d..db33365 100644 --- a/Swift/QtUI/QtUIFactory.h +++ b/Swift/QtUI/QtUIFactory.h @@ -10,6 +10,7 @@ #include <QPointer> #include <Swift/Controllers/UIInterfaces/UIFactory.h> +#include <Swift/QtUI/QtUIPreferences.h> class QSplitter; @@ -26,7 +27,7 @@ namespace Swift { class QtUIFactory : public QObject, public UIFactory { Q_OBJECT public: - QtUIFactory(QtSettingsProvider* settings, QtChatTabs* tabs, QSplitter* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, bool startMinimized, bool eagleMode); + QtUIFactory(QtSettingsProvider* settings, QtChatTabs* tabs, QSplitter* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, bool startMinimized, bool eagleMode, QtUIPreferences* uiPreferences); virtual XMLConsoleWidget* createXMLConsoleWidget(); virtual MainWindow* createMainWindow(UIEventStream* eventStream); @@ -58,5 +59,6 @@ namespace Swift { bool startMinimized; int chatFontSize; bool eagleMode; + QtUIPreferences* uiPreferences; }; } diff --git a/Swift/QtUI/QtUIPreferences.cpp b/Swift/QtUI/QtUIPreferences.cpp new file mode 100644 index 0000000..3118178 --- /dev/null +++ b/Swift/QtUI/QtUIPreferences.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swift/QtUI/QtUIPreferences.h> + +namespace Swift { +QtUIPreferences::QtUIPreferences() : compactRosters_(false) { + +} + +QtUIPreferences::~QtUIPreferences() { + +} + +void QtUIPreferences::setCompactRosters(bool compact) { + compactRosters_ = compact; + emit onCompactRostersChanged(compact); +} + +bool QtUIPreferences::getCompactRosters() { + return compactRosters_; +} + +} diff --git a/Swift/QtUI/QtUIPreferences.h b/Swift/QtUI/QtUIPreferences.h new file mode 100644 index 0000000..e537e80 --- /dev/null +++ b/Swift/QtUI/QtUIPreferences.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QObject> + +namespace Swift { + class QtUIPreferences : public QObject { + Q_OBJECT + public: + QtUIPreferences(); + ~QtUIPreferences(); + bool getCompactRosters(); + public slots: + void setCompactRosters(bool compact); + signals: + void onCompactRostersChanged(bool /*now*/); + private: + bool compactRosters_; + }; +}
\ No newline at end of file diff --git a/Swift/QtUI/Roster/DelegateCommons.cpp b/Swift/QtUI/Roster/DelegateCommons.cpp index 290794d..0dc8a52 100644 --- a/Swift/QtUI/Roster/DelegateCommons.cpp +++ b/Swift/QtUI/Roster/DelegateCommons.cpp @@ -17,7 +17,7 @@ void DelegateCommons::drawElidedText(QPainter* painter, const QRect& region, con painter->drawText(region, flags, adjustedText); } -void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount) const { +void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount, bool compact) const { painter->save(); QRect fullRegion(option.rect); if ( option.state & QStyle::State_Selected ) { @@ -34,17 +34,19 @@ void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem QRect avatarRegion(QPoint(presenceIconRegion.right() - presenceIconWidth / 2, presenceIconRegion.top()), QSize(calculatedAvatarSize, calculatedAvatarSize)); QPixmap avatarPixmap; - if (!avatarPath.isEmpty()) { + if (!compact && !avatarPath.isEmpty()) { QString scaledAvatarPath = QtScaledAvatarCache(avatarRegion.height()).getScaledAvatarPath(avatarPath); if (QFileInfo(scaledAvatarPath).exists()) { avatarPixmap.load(scaledAvatarPath); } } - if (avatarPixmap.isNull()) { + if (!compact && avatarPixmap.isNull()) { avatarPixmap = QPixmap(":/icons/avatar.png").scaled(avatarRegion.height(), avatarRegion.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation); } - painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap); + if (!compact) { + painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap); + } //Paint the presence icon over the top of the avatar presenceIcon.paint(painter, presenceIconRegion, Qt::AlignBottom | Qt::AlignHCenter); @@ -52,7 +54,7 @@ void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem QFontMetrics nameMetrics(nameFont); painter->setFont(nameFont); int extraFontWidth = nameMetrics.width("H"); - int leftOffset = avatarRegion.right() + horizontalMargin * 2 + extraFontWidth / 2; + int leftOffset = (compact ? presenceIconRegion : avatarRegion).right() + horizontalMargin * 2 + extraFontWidth / 2; QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0/*-leftOffset*/, 0)); int nameHeight = nameMetrics.height() + verticalMargin; @@ -60,12 +62,13 @@ void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem DelegateCommons::drawElidedText(painter, nameRegion, name); + if (!compact) { + painter->setFont(detailFont); + painter->setPen(QPen(QColor(160,160,160))); - painter->setFont(detailFont); - painter->setPen(QPen(QColor(160,160,160))); - - QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0)); - DelegateCommons::drawElidedText(painter, statusTextRegion, statusText); + QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0)); + DelegateCommons::drawElidedText(painter, statusTextRegion, statusText); + } if (unreadCount > 0) { QRect unreadRect(fullRegion.right() - unreadCountSize - horizontalMargin, fullRegion.top() + (fullRegion.height() - unreadCountSize) / 2, unreadCountSize, unreadCountSize); @@ -84,11 +87,11 @@ void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem painter->restore(); } -QSize DelegateCommons::contactSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const { - int heightByAvatar = avatarSize + verticalMargin * 2; +QSize DelegateCommons::contactSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/, bool compact ) const { + int heightByAvatar = (compact ? presenceIconHeight : avatarSize) + verticalMargin * 2; QFontMetrics nameMetrics(nameFont); QFontMetrics statusMetrics(detailFont); - int sizeByText = 2 * verticalMargin + nameMetrics.height() + statusMetrics.height(); + int sizeByText = 2 * verticalMargin + nameMetrics.height() + (compact ? 0 : statusMetrics.height()); //Doesn't work, yay! FIXME: why? //QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150, avatarSize_ + margin_ * 2); //qDebug() << "Returning size" << size; diff --git a/Swift/QtUI/Roster/DelegateCommons.h b/Swift/QtUI/Roster/DelegateCommons.h index e5e4ff9..8732598 100644 --- a/Swift/QtUI/Roster/DelegateCommons.h +++ b/Swift/QtUI/Roster/DelegateCommons.h @@ -25,8 +25,8 @@ namespace Swift { static void drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags = Qt::AlignTop); - QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; - void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount) const; + QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index, bool compact) const; + void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount, bool compact) const; int detailFontSizeDrop; QFont nameFont; diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.cpp b/Swift/QtUI/Roster/QtOccupantListWidget.cpp index d7bb875..f864919 100644 --- a/Swift/QtUI/Roster/QtOccupantListWidget.cpp +++ b/Swift/QtUI/Roster/QtOccupantListWidget.cpp @@ -19,7 +19,7 @@ namespace Swift { -QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, QWidget* parent) : QtTreeWidget(eventStream, parent) { +QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent) : QtTreeWidget(eventStream, uiPreferences, parent) { } diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.h b/Swift/QtUI/Roster/QtOccupantListWidget.h index ef29c00..da7c463 100644 --- a/Swift/QtUI/Roster/QtOccupantListWidget.h +++ b/Swift/QtUI/Roster/QtOccupantListWidget.h @@ -12,11 +12,12 @@ #include "Swift/Controllers/UIInterfaces/ChatWindow.h" namespace Swift { +class QtUIPreferences; class QtOccupantListWidget : public QtTreeWidget { Q_OBJECT public: - QtOccupantListWidget(UIEventStream* eventStream, QWidget* parent = 0); + QtOccupantListWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent = 0); virtual ~QtOccupantListWidget(); void setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions); boost::signal<void (ChatWindow::OccupantAction, ContactRosterItem*)> onOccupantActionSelected; diff --git a/Swift/QtUI/Roster/QtRosterWidget.cpp b/Swift/QtUI/Roster/QtRosterWidget.cpp index 4c96695..ac4b500 100644 --- a/Swift/QtUI/Roster/QtRosterWidget.cpp +++ b/Swift/QtUI/Roster/QtRosterWidget.cpp @@ -23,7 +23,7 @@ namespace Swift { -QtRosterWidget::QtRosterWidget(UIEventStream* eventStream, QWidget* parent) : QtTreeWidget(eventStream, parent) { +QtRosterWidget::QtRosterWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent) : QtTreeWidget(eventStream, uiPreferences, parent) { } diff --git a/Swift/QtUI/Roster/QtRosterWidget.h b/Swift/QtUI/Roster/QtRosterWidget.h index f870237..01f4726 100644 --- a/Swift/QtUI/Roster/QtRosterWidget.h +++ b/Swift/QtUI/Roster/QtRosterWidget.h @@ -9,10 +9,12 @@ #include "Swift/QtUI/Roster/QtTreeWidget.h" namespace Swift { +class QtUIPreferences; + class QtRosterWidget : public QtTreeWidget { Q_OBJECT public: - QtRosterWidget(UIEventStream* eventStream, QWidget* parent = 0); + QtRosterWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent = 0); virtual ~QtRosterWidget(); public slots: void handleEditUserActionTriggered(bool checked); diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index 690515d..4382125 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -10,21 +10,23 @@ #include <QUrl> -#include "Swiften/Base/Platform.h" -#include "Swift/Controllers/Roster/ContactRosterItem.h" -#include "Swift/Controllers/Roster/GroupRosterItem.h" -#include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" -#include "Swift/Controllers/UIEvents/SendFileUIEvent.h" -#include "QtSwiftUtil.h" +#include <Swiften/Base/Platform.h> +#include <Swift/Controllers/Roster/ContactRosterItem.h> +#include <Swift/Controllers/Roster/GroupRosterItem.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> +#include <Swift/Controllers/UIEvents/SendFileUIEvent.h> +#include <QtSwiftUtil.h> +#include <Swift/QtUI/QtUIPreferences.h> namespace Swift { -QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QWidget* parent) : QTreeView(parent) { +QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent) : QTreeView(parent) { eventStream_ = eventStream; + uiPreferences_ = uiPreferences; model_ = new RosterModel(this); setModel(model_); - delegate_ = new RosterDelegate(this); + delegate_ = new RosterDelegate(this, uiPreferences_->getCompactRosters()); setItemDelegate(delegate_); setHeaderHidden(true); #ifdef SWIFT_PLATFORM_MACOSX @@ -43,6 +45,7 @@ QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QWidget* parent) : QTreeV connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(handleExpanded(const QModelIndex&))); connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(handleCollapsed(const QModelIndex&))); connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&))); + connect(uiPreferences_, SIGNAL(onCompactRostersChanged(bool)), this, SLOT(handleCompactRostersToggled(bool))); } QtTreeWidget::~QtTreeWidget() { @@ -50,6 +53,11 @@ QtTreeWidget::~QtTreeWidget() { delete delegate_; } +void QtTreeWidget::handleCompactRostersToggled(bool compact) { + delegate_->setCompact(compact); + repaint(); +} + void QtTreeWidget::setRosterModel(Roster* roster) { roster_ = roster; model_->setRoster(roster); diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h index 271fbd5..705c039 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.h +++ b/Swift/QtUI/Roster/QtTreeWidget.h @@ -16,11 +16,12 @@ namespace Swift { class UIEventStream; +class QtUIPreferences; class QtTreeWidget : public QTreeView{ Q_OBJECT public: - QtTreeWidget(UIEventStream* eventStream, QWidget* parent = 0); + QtTreeWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent = 0); ~QtTreeWidget(); void show(); QtTreeWidgetItem* getRoot(); @@ -34,6 +35,7 @@ class QtTreeWidget : public QTreeView{ void handleExpanded(const QModelIndex&); void handleCollapsed(const QModelIndex&); void handleClicked(const QModelIndex&); + void handleCompactRostersToggled(bool compact); protected: void dragEnterEvent(QDragEnterEvent* event); void dropEvent(QDropEvent* event); @@ -53,6 +55,7 @@ class QtTreeWidget : public QTreeView{ Roster* roster_; RosterDelegate* delegate_; QtTreeWidgetItem* treeRoot_; + QtUIPreferences* uiPreferences_; }; } diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index e40907a..7e6428b 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -24,7 +24,7 @@ namespace Swift { -RosterDelegate::RosterDelegate(QtTreeWidget* tree) { +RosterDelegate::RosterDelegate(QtTreeWidget* tree, bool compact) : compact_(compact) { tree_ = tree; groupDelegate_ = new GroupItemDelegate(); } @@ -32,6 +32,10 @@ RosterDelegate::RosterDelegate(QtTreeWidget* tree) { RosterDelegate::~RosterDelegate() { delete groupDelegate_; } + +void RosterDelegate::setCompact(bool compact) { + compact_ = compact; +} QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); @@ -42,7 +46,7 @@ QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelI } QSize RosterDelegate::contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { - return common_.contactSizeHint(option, index); + return common_.contactSizeHint(option, index, compact_); } void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { @@ -71,7 +75,7 @@ void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& : QIcon(":/icons/offline.png"); QString name = index.data(Qt::DisplayRole).toString(); QString statusText = index.data(StatusTextRole).toString(); - common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, 0); + common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, 0, compact_); } } diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h index 253c11a..c5db7ef 100644 --- a/Swift/QtUI/Roster/RosterDelegate.h +++ b/Swift/QtUI/Roster/RosterDelegate.h @@ -17,14 +17,17 @@ namespace Swift { class QtTreeWidget; class RosterDelegate : public QStyledItemDelegate { public: - RosterDelegate(QtTreeWidget* tree); + RosterDelegate(QtTreeWidget* tree, bool compact); ~RosterDelegate(); QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + public slots: + void setCompact(bool compact); private: QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; void paintGroup(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + bool compact_; DelegateCommons common_; GroupItemDelegate* groupDelegate_; QtTreeWidget* tree_; diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 9417f63..932a1fa 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -138,6 +138,7 @@ sources = [ "QtFileTransferJSBridge.cpp", "QtMUCConfigurationWindow.cpp", "QtAffiliationEditor.cpp", + "QtUIPreferences.cpp" ] myenv["SWIFT_VERSION"] = Version.getBuildVersion(env.Dir("#").abspath, "swift") |