diff options
Diffstat (limited to 'Swift/QtUI')
| -rw-r--r-- | Swift/QtUI/QtMainWindow.cpp | 4 | ||||
| -rw-r--r-- | Swift/QtUI/QtMainWindow.h | 1 | ||||
| -rw-r--r-- | Swift/QtUI/QtRosterHeader.cpp | 28 | ||||
| -rw-r--r-- | Swift/QtUI/QtRosterHeader.h | 8 |
4 files changed, 35 insertions, 6 deletions
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 1acc519..31a8234 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -1,398 +1,402 @@ /* * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swift/QtUI/QtMainWindow.h> #include <boost/optional.hpp> #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <QBoxLayout> #include <QComboBox> #include <QLineEdit> #include <QListWidget> #include <QListWidgetItem> #include <QPushButton> #include <QMenuBar> #include <QToolBar> #include <QAction> #include <QTabWidget> #include <Swiften/Base/Platform.h> #include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h> #include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h> #include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h> #include <Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h> #include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h> #include <Swift/Controllers/UIEvents/RequestBlockListDialogUIEvent.h> #include <Swift/Controllers/SettingConstants.h> #include <Swift/QtUI/Roster/QtFilterWidget.h> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtTabWidget.h> #include <Swift/QtUI/QtSettingsProvider.h> #include <Swift/QtUI/QtLoginWindow.h> #include <Swift/QtUI/Roster/QtRosterWidget.h> #include <Swift/QtUI/QtUISettingConstants.h> #if defined(SWIFTEN_PLATFORM_MACOSX) #include <Swift/QtUI/CocoaUIHelpers.h> #elif defined(SWIFTEN_PLATFORM_WINDOWS) #include <Swift/QtUI/WinUIHelpers.h> #else #include <Swift/QtUI/QtCertificateViewerDialog.h> #endif namespace Swift { QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStream, QtLoginWindow::QtMenus loginMenus, StatusCache* statusCache, bool emoticonsExist) : QWidget(), MainWindow(false), loginMenus_(loginMenus) { uiEventStream_ = uiEventStream; settings_ = settings; setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this); mainLayout->setContentsMargins(0,0,0,0); mainLayout->setSpacing(0); meView_ = new QtRosterHeader(settings, statusCache, this); mainLayout->addWidget(meView_); connect(meView_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleStatusChanged(StatusShow::Type, const QString&))); connect(meView_, SIGNAL(onEditProfileRequest()), this, SLOT(handleEditProfileRequest())); connect(meView_, SIGNAL(onShowCertificateInfo()), this, SLOT(handleShowCertificateInfo())); tabs_ = new QtTabWidget(this); #if QT_VERSION >= 0x040500 tabs_->setDocumentMode(true); #endif tabs_->setTabPosition(QTabWidget::South); mainLayout->addWidget(tabs_); contactsTabWidget_ = new QWidget(this); contactsTabWidget_->setContentsMargins(0, 0, 0, 0); QBoxLayout *contactTabLayout = new QBoxLayout(QBoxLayout::TopToBottom, contactsTabWidget_); contactsTabWidget_->setLayout(contactTabLayout); contactTabLayout->setSpacing(0); contactTabLayout->setContentsMargins(0, 0, 0, 0); treeWidget_ = new QtRosterWidget(uiEventStream_, settings_, this); contactTabLayout->addWidget(treeWidget_); new QtFilterWidget(this, treeWidget_, uiEventStream_, contactTabLayout); tabs_->addTab(contactsTabWidget_, tr("&Contacts")); eventWindow_ = new QtEventWindow(uiEventStream_); connect(eventWindow_, SIGNAL(onNewEventCountUpdated(int)), this, SLOT(handleEventCountUpdated(int))); chatListWindow_ = new QtChatListWindow(uiEventStream_, settings_); connect(chatListWindow_, SIGNAL(onCountUpdated(int)), this, SLOT(handleChatCountUpdated(int))); tabs_->addTab(chatListWindow_, tr("C&hats")); tabs_->addTab(eventWindow_, tr("&Notices")); tabs_->setCurrentIndex(settings_->getSetting(QtUISettingConstants::CURRENT_ROSTER_TAB)); connect(tabs_, SIGNAL(currentChanged(int)), this, SLOT(handleTabChanged(int))); tabBarCombo_ = NULL; if (settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)) { tabs_->tabBar()->hide(); tabBarCombo_ = new QComboBox(this); tabBarCombo_->setAccessibleName("Current View"); tabBarCombo_->addItem(tr("Contacts")); tabBarCombo_->addItem(tr("Chats")); tabBarCombo_->addItem(tr("Notices")); tabBarCombo_->setCurrentIndex(tabs_->currentIndex()); mainLayout->addWidget(tabBarCombo_); connect(tabBarCombo_, SIGNAL(currentIndexChanged(int)), tabs_, SLOT(setCurrentIndex(int))); } this->setLayout(mainLayout); QMenu* viewMenu = new QMenu(tr("&View"), this); menus_.push_back(viewMenu); compactRosterAction_ = new QAction(tr("&Compact Roster"), this); compactRosterAction_->setCheckable(true); compactRosterAction_->setChecked(false); connect(compactRosterAction_, SIGNAL(toggled(bool)), SLOT(handleCompactRosterToggled(bool))); viewMenu->addAction(compactRosterAction_); handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); showOfflineAction_ = new QAction(tr("&Show offline contacts"), this); showOfflineAction_->setCheckable(true); showOfflineAction_->setChecked(false); connect(showOfflineAction_, SIGNAL(toggled(bool)), SLOT(handleShowOfflineToggled(bool))); viewMenu->addAction(showOfflineAction_); handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE)); if (emoticonsExist) { showEmoticonsAction_ = new QAction(tr("&Show Emoticons"), this); showEmoticonsAction_->setCheckable(true); showEmoticonsAction_->setChecked(false); connect(showEmoticonsAction_, SIGNAL(toggled(bool)), SLOT(handleShowEmoticonsToggled(bool))); viewMenu->addAction(showEmoticonsAction_); handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS)); } //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); connect(editProfileAction, SIGNAL(triggered()), SLOT(handleEditProfileAction())); actionsMenu->addAction(editProfileAction); QAction* joinMUCAction = new QAction(tr("Enter &Room…"), this); connect(joinMUCAction, SIGNAL(triggered()), SLOT(handleJoinMUCAction())); actionsMenu->addAction(joinMUCAction); #ifdef SWIFT_EXPERIMENTAL_HISTORY QAction* viewLogsAction = new QAction(tr("&View History…"), this); connect(viewLogsAction, SIGNAL(triggered()), SLOT(handleViewLogsAction())); actionsMenu->addAction(viewLogsAction); #endif openBlockingListEditor_ = new QAction(tr("Edit &Blocking List…"), this); connect(openBlockingListEditor_, SIGNAL(triggered()), SLOT(handleEditBlockingList())); actionsMenu->addAction(openBlockingListEditor_); openBlockingListEditor_->setVisible(false); addUserAction_ = new QAction(tr("&Add Contact…"), this); addUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); addUserAction_->setShortcutContext(Qt::ApplicationShortcut); connect(addUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleAddUserActionTriggered(bool))); actionsMenu->addAction(addUserAction_); editUserAction_ = new QAction(tr("&Edit Selected Contact…"), this); connect(editUserAction_, SIGNAL(triggered(bool)), treeWidget_, SLOT(handleEditUserActionTriggered(bool))); actionsMenu->addAction(editUserAction_); editUserAction_->setEnabled(false); chatUserAction_ = new QAction(tr("Start &Chat…"), this); chatUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); chatUserAction_->setShortcutContext(Qt::ApplicationShortcut); connect(chatUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleChatUserActionTriggered(bool))); actionsMenu->addAction(chatUserAction_); serverAdHocMenu_ = new QMenu(tr("Run Server Command"), this); actionsMenu->addMenu(serverAdHocMenu_); actionsMenu->addSeparator(); QAction* signOutAction = new QAction(tr("&Sign Out"), this); connect(signOutAction, SIGNAL(triggered()), SLOT(handleSignOutAction())); actionsMenu->addAction(signOutAction); toggleRequestDeliveryReceipts_ = new QAction(tr("&Request Delivery Receipts"), this); toggleRequestDeliveryReceipts_->setCheckable(true); toggleRequestDeliveryReceipts_->setChecked(settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS)); connect(toggleRequestDeliveryReceipts_, SIGNAL(toggled(bool)), SLOT(handleToggleRequestDeliveryReceipts(bool))); QList< QAction* > generalMenuActions = loginMenus_.generalMenu->actions(); loginMenus_.generalMenu->insertAction(generalMenuActions.at(generalMenuActions.count()-2),toggleRequestDeliveryReceipts_); treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QAction::setEnabled, editUserAction_, _1)); setAvailableAdHocCommands(std::vector<DiscoItems::Item>()); QAction* adHocAction = new QAction(tr("Collecting commands..."), this); adHocAction->setEnabled(false); serverAdHocMenu_->addAction(adHocAction); serverAdHocCommandActions_.append(adHocAction); settings_->onSettingChanged.connect(boost::bind(&QtMainWindow::handleSettingChanged, this, _1)); } QtMainWindow::~QtMainWindow() { settings_->onSettingChanged.disconnect(boost::bind(&QtMainWindow::handleSettingChanged, this, _1)); } void QtMainWindow::handleTabChanged(int index) { settings_->storeSetting(QtUISettingConstants::CURRENT_ROSTER_TAB, index); } void QtMainWindow::handleToggleRequestDeliveryReceipts(bool enabled) { settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, enabled); } void QtMainWindow::handleShowCertificateInfo() { onShowCertificateRequest(); } void QtMainWindow::handleEditBlockingList() { uiEventStream_->send(boost::make_shared<RequestBlockListDialogUIEvent>()); } QtEventWindow* QtMainWindow::getEventWindow() { return eventWindow_; } QtChatListWindow* QtMainWindow::getChatListWindow() { return chatListWindow_; } void QtMainWindow::setRosterModel(Roster* roster) { treeWidget_->setRosterModel(roster); } void QtMainWindow::handleEditProfileRequest() { uiEventStream_->send(boost::make_shared<RequestProfileEditorUIEvent>()); } void QtMainWindow::handleEventCountUpdated(int count) { QColor eventTabColor = (count == 0) ? QColor() : QColor(255, 0, 0); // invalid resets to default int eventIndex = 2; tabs_->tabBar()->setTabTextColor(eventIndex, eventTabColor); QString text = tr("&Notices"); if (count > 0) { text += QString(" (%1)").arg(count); } tabs_->setTabText(eventIndex, text); } void QtMainWindow::handleChatCountUpdated(int count) { QColor chatTabColor = (count == 0) ? QColor() : QColor(255, 0, 0); // invalid resets to default int chatIndex = 1; tabs_->tabBar()->setTabTextColor(chatIndex, chatTabColor); QString text = tr("&Chats"); if (count > 0) { text += QString(" (%1)").arg(count); } tabs_->setTabText(chatIndex, text); } void QtMainWindow::handleAddUserActionTriggered(bool /*checked*/) { boost::shared_ptr<UIEvent> event(new RequestAddUserDialogUIEvent()); uiEventStream_->send(event); } void QtMainWindow::handleChatUserActionTriggered(bool /*checked*/) { boost::shared_ptr<UIEvent> event(new RequestChatWithUserDialogUIEvent()); uiEventStream_->send(event); } void QtMainWindow::handleSignOutAction() { loginMenus_.generalMenu->removeAction(toggleRequestDeliveryReceipts_); onSignOutRequest(); } void QtMainWindow::handleEditProfileAction() { uiEventStream_->send(boost::make_shared<RequestProfileEditorUIEvent>()); } void QtMainWindow::handleJoinMUCAction() { uiEventStream_->send(boost::make_shared<RequestJoinMUCUIEvent>()); } void QtMainWindow::handleViewLogsAction() { uiEventStream_->send(boost::make_shared<RequestHistoryUIEvent>()); } void QtMainWindow::handleStatusChanged(StatusShow::Type showType, const QString &statusMessage) { onChangeStatusRequest(showType, Q2PSTRING(statusMessage)); } void QtMainWindow::handleSettingChanged(const std::string& settingPath) { if (settingPath == SettingConstants::SHOW_OFFLINE.getKey()) { handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE)); } if (settingPath == QtUISettingConstants::SHOW_EMOTICONS.getKey()) { handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS)); } if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) { toggleRequestDeliveryReceipts_->setChecked(settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS)); } if (settingPath == QtUISettingConstants::COMPACT_ROSTER.getKey()) { handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); } } void QtMainWindow::handleCompactRosterToggled(bool state) { settings_->storeSetting(QtUISettingConstants::COMPACT_ROSTER, state); compactRosterAction_->setChecked(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); } void QtMainWindow::handleShowOfflineToggled(bool state) { settings_->storeSetting(SettingConstants::SHOW_OFFLINE, state); showOfflineAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_OFFLINE)); } void QtMainWindow::handleShowEmoticonsToggled(bool state) { settings_->storeSetting(QtUISettingConstants::SHOW_EMOTICONS, state); showEmoticonsAction_->setChecked(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS)); } void QtMainWindow::setMyNick(const std::string& nick) { meView_->setNick(P2QSTRING(nick)); } void QtMainWindow::setMyJID(const JID& jid) { meView_->setJID(P2QSTRING(jid.toBare().toString())); } void QtMainWindow::setMyAvatarPath(const std::string& path) { meView_->setAvatar(P2QSTRING(path)); } void QtMainWindow::setMyStatusText(const std::string& status) { meView_->setStatusText(P2QSTRING(status)); } void QtMainWindow::setMyStatusType(StatusShow::Type type) { meView_->setStatusType(type); } +void QtMainWindow::setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) { + meView_->setContactRosterItem(contact); +} + void QtMainWindow::setConnecting() { meView_->setConnecting(); } void QtMainWindow::setStreamEncryptionStatus(bool tlsInPlaceAndValid) { meView_->setStreamEncryptionStatus(tlsInPlaceAndValid); } void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain) { openCertificateDialog(chain, this); } void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent) { #if defined(SWIFTEN_PLATFORM_MACOSX) CocoaUIHelpers::displayCertificateChainAsSheet(parent, chain); #elif defined(SWIFTEN_PLATFORM_WINDOWS) WinUIHelpers::displayCertificateChainAsSheet(parent, chain); #else QtCertificateViewerDialog::displayCertificateChainAsSheet(parent, chain); #endif } void QtMainWindow::handleAdHocActionTriggered(bool /*checked*/) { QAction* action = qobject_cast<QAction*>(sender()); assert(action); DiscoItems::Item command = serverAdHocCommands_[serverAdHocCommandActions_.indexOf(action)]; uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestAdHocUIEvent(command))); } void QtMainWindow::setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands) { serverAdHocCommands_ = commands; foreach (QAction* action, serverAdHocCommandActions_) { delete action; } serverAdHocMenu_->clear(); serverAdHocCommandActions_.clear(); foreach (DiscoItems::Item command, commands) { QAction* action = new QAction(P2QSTRING(command.getName()), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(handleAdHocActionTriggered(bool))); serverAdHocMenu_->addAction(action); serverAdHocCommandActions_.append(action); } if (serverAdHocCommandActions_.isEmpty()) { QAction* action = new QAction(tr("No Available Commands"), this); action->setEnabled(false); serverAdHocMenu_->addAction(action); serverAdHocCommandActions_.append(action); } } void QtMainWindow::setBlockingCommandAvailable(bool isAvailable) { openBlockingListEditor_->setVisible(isAvailable); } } diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h index c489a9e..f1f6900 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -1,105 +1,106 @@ /* * Copyright (c) 2010-2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <vector> #include <QWidget> #include <QMenu> #include <QList> #include <Swift/Controllers/UIInterfaces/MainWindow.h> #include <Swift/QtUI/QtRosterHeader.h> #include <Swift/QtUI/EventViewer/QtEventWindow.h> #include <Swift/QtUI/ChatList/QtChatListWindow.h> #include <Swift/QtUI/QtLoginWindow.h> class QComboBox; class QLineEdit; class QPushButton; class QToolBar; class QAction; class QMenu; class QTabWidget; namespace Swift { class QtRosterWidget; class TreeWidget; class UIEventStream; class QtTabWidget; class SettingsProvider; class QtUIPreferences; class StatusCache; class QtMainWindow : public QWidget, public MainWindow { Q_OBJECT public: QtMainWindow(SettingsProvider*, UIEventStream* eventStream, QtLoginWindow::QtMenus loginMenus, StatusCache* statusCache, bool emoticonsExist); virtual ~QtMainWindow(); std::vector<QMenu*> getMenus() {return menus_;} void setMyNick(const std::string& name); void setMyJID(const JID& jid); void setMyAvatarPath(const std::string& path); void setMyStatusText(const std::string& status); void setMyStatusType(StatusShow::Type type); + void setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact); void setConnecting(); void setStreamEncryptionStatus(bool tlsInPlaceAndValid); void openCertificateDialog(const std::vector<Certificate::ref>& chain); static void openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent); QtEventWindow* getEventWindow(); QtChatListWindow* getChatListWindow(); void setRosterModel(Roster* roster); void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands); void setBlockingCommandAvailable(bool isAvailable); private slots: void handleStatusChanged(StatusShow::Type showType, const QString &statusMessage); void handleSettingChanged(const std::string& settingPath); void handleCompactRosterToggled(bool); void handleShowOfflineToggled(bool); void handleShowEmoticonsToggled(bool); void handleJoinMUCAction(); void handleViewLogsAction(); void handleSignOutAction(); void handleEditProfileAction(); void handleAddUserActionTriggered(bool checked); void handleChatUserActionTriggered(bool checked); void handleAdHocActionTriggered(bool checked); void handleEventCountUpdated(int count); void handleChatCountUpdated(int count); void handleEditProfileRequest(); void handleTabChanged(int index); void handleToggleRequestDeliveryReceipts(bool enabled); void handleShowCertificateInfo(); void handleEditBlockingList(); private: SettingsProvider* settings_; QtLoginWindow::QtMenus loginMenus_; std::vector<QMenu*> menus_; QtRosterWidget* treeWidget_; QtRosterHeader* meView_; QAction* addUserAction_; QAction* editUserAction_; QAction* chatUserAction_; QAction* showOfflineAction_; QAction* compactRosterAction_; QAction* showEmoticonsAction_; QAction* openBlockingListEditor_; QAction* toggleRequestDeliveryReceipts_; QMenu* serverAdHocMenu_; QtTabWidget* tabs_; QComboBox* tabBarCombo_; QWidget* contactsTabWidget_; QWidget* eventsTabWidget_; QtEventWindow* eventWindow_; QtChatListWindow* chatListWindow_; UIEventStream* uiEventStream_; std::vector<DiscoItems::Item> serverAdHocCommands_; QList<QAction*> serverAdHocCommandActions_; }; } diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp index 2c8f244..69a0ef6 100644 --- a/Swift/QtUI/QtRosterHeader.cpp +++ b/Swift/QtUI/QtRosterHeader.cpp @@ -1,116 +1,134 @@ /* * Copyright (c) 2010-2014 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "QtRosterHeader.h" -#include <QHBoxLayout> -#include <QVBoxLayout> +#include <QBitmap> +#include <qdebug.h> #include <QFileInfo> +#include <QHBoxLayout> +#include <QHelpEvent> #include <QIcon> -#include <QSizePolicy> -#include <qdebug.h> #include <QMouseEvent> #include <QPainter> -#include <QBitmap> +#include <QSizePolicy> +#include <QToolTip> +#include <QVBoxLayout> #include "QtStatusWidget.h" #include <Swift/QtUI/QtElidingLabel.h> #include <Swift/QtUI/QtClickableLabel.h> #include <Swift/QtUI/QtNameWidget.h> +#include <Swift/QtUI/Roster/RosterTooltip.h> #include "QtScaledAvatarCache.h" namespace Swift { QtRosterHeader::QtRosterHeader(SettingsProvider* settings, StatusCache* statusCache, QWidget* parent) : QWidget(parent), statusEdit_(NULL) { QHBoxLayout* topLayout = new QHBoxLayout(); topLayout->setSpacing(3); topLayout->setContentsMargins(4,4,4,4); setLayout(topLayout); setMinimumHeight(50); setMaximumHeight(50); avatarLabel_ = new QtClickableLabel(this); avatarLabel_->setMinimumSize(avatarSize_, avatarSize_); avatarLabel_->setMaximumSize(avatarSize_, avatarSize_); avatarLabel_->setAlignment(Qt::AlignCenter); setAvatar(":/icons/avatar.png"); avatarLabel_->setScaledContents(false); topLayout->addWidget(avatarLabel_); connect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest())); QVBoxLayout* rightLayout = new QVBoxLayout(); rightLayout->setSpacing(4); rightLayout->setContentsMargins(4,0,0,0); topLayout->addLayout(rightLayout); QHBoxLayout* nameAndSecurityLayout = new QHBoxLayout(); nameAndSecurityLayout->setContentsMargins(4,0,0,0); nameWidget_ = new QtNameWidget(settings, this); connect(nameWidget_, SIGNAL(onChangeNickRequest()), this, SIGNAL(onEditProfileRequest())); nameAndSecurityLayout->addWidget(nameWidget_); securityInfoButton_ = new QToolButton(this); securityInfoButton_->setStyleSheet("QToolButton { border: none; } QToolButton:hover { border: 1px solid #bebebe; } QToolButton:pressed { border: 1px solid #757575; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #777777, stop: 1 #d4d4d4);}"); //securityInfoButton_->setAutoRaise(true); securityInfoButton_->setIcon(QIcon(":/icons/lock.png")); securityInfoButton_->setToolTip(tr("Connection is secured")); connect(securityInfoButton_, SIGNAL(clicked()), this, SIGNAL(onShowCertificateInfo())); nameAndSecurityLayout->addWidget(securityInfoButton_); rightLayout->addLayout(nameAndSecurityLayout); statusWidget_ = new QtStatusWidget(statusCache, this); connect(statusWidget_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleChangeStatusRequest(StatusShow::Type, const QString&))); rightLayout->addWidget(statusWidget_); show(); } void QtRosterHeader::handleChangeStatusRequest(StatusShow::Type type, const QString& text) { emit onChangeStatusRequest(type, text); } void QtRosterHeader::setStatusText(const QString& statusMessage) { statusWidget_->setStatusText(statusMessage); } void QtRosterHeader::setStatusType(StatusShow::Type type) { statusWidget_->setStatusType(type); } void QtRosterHeader::setConnecting() { statusWidget_->setConnecting(); } void QtRosterHeader::setStreamEncryptionStatus(bool tlsInPlace) { securityInfoButton_->setVisible(tlsInPlace); } +bool QtRosterHeader::event(QEvent* event) { + if (event->type() == QEvent::ToolTip) { + QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); + QtScaledAvatarCache scaledAvatarCache(avatarSize_); + QString text = RosterTooltip::buildDetailedTooltip(contact_.get(), &scaledAvatarCache); + QToolTip::showText(helpEvent->globalPos(), text); + return true; + } + return QWidget::event(event); +} + void QtRosterHeader::setAvatar(const QString& path) { QString scaledAvatarPath = QtScaledAvatarCache(avatarSize_).getScaledAvatarPath(path); QPixmap avatar; if (QFileInfo(scaledAvatarPath).exists()) { avatar.load(scaledAvatarPath); } else { avatar = QPixmap(":/icons/avatar.png").scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation); } avatarLabel_->setPixmap(avatar); } void QtRosterHeader::setNick(const QString& nick) { nameWidget_->setNick(nick); } +void QtRosterHeader::setContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) { + contact_ = contact; +} + void QtRosterHeader::setJID(const QString& jid) { nameWidget_->setJID(jid); } const int QtRosterHeader::avatarSize_ = 40; } diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h index ad19178..eafbc02 100644 --- a/Swift/QtUI/QtRosterHeader.h +++ b/Swift/QtUI/QtRosterHeader.h @@ -1,58 +1,64 @@ /* * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <QWidget> #include <QLabel> #include <QPixmap> #include <QSize> #include <QToolButton> #include <string> -#include "Swiften/Elements/StatusShow.h" +#include <Swiften/Elements/StatusShow.h> +#include <Swiften/Elements/VCard.h> +#include <Swift/Controllers/Roster/ContactRosterItem.h> #include "QtTextEdit.h" class QHBoxLayout; namespace Swift { class QtClickableLabel; class QtStatusWidget; class QtNameWidget; class SettingsProvider; class StatusCache; class QtRosterHeader : public QWidget { Q_OBJECT public: QtRosterHeader(SettingsProvider* settings, StatusCache* statusCache, QWidget* parent = NULL); void setAvatar(const QString& path); void setJID(const QString& jid); void setNick(const QString& nick); + void setContactRosterItem(boost::shared_ptr<ContactRosterItem> contact); void setStatusText(const QString& statusMessage); void setStatusType(StatusShow::Type type); void setConnecting(); void setStreamEncryptionStatus(bool tlsInPlace); + private: + bool event(QEvent* event); signals: void onChangeStatusRequest(StatusShow::Type showType, const QString &statusMessage); void onEditProfileRequest(); void onShowCertificateInfo(); private slots: void handleChangeStatusRequest(StatusShow::Type type, const QString &statusMessage); private: QString name_; QtClickableLabel* avatarLabel_; QtNameWidget* nameWidget_; QtTextEdit* statusEdit_; QtStatusWidget* statusWidget_; QToolButton* securityInfoButton_; static const int avatarSize_; + boost::shared_ptr<ContactRosterItem> contact_; }; } |
Swift