diff options
Diffstat (limited to 'Swift/QtUI/QtStatusWidget.cpp')
-rw-r--r-- | Swift/QtUI/QtStatusWidget.cpp | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp index 0e2731a..8cc366a 100644 --- a/Swift/QtUI/QtStatusWidget.cpp +++ b/Swift/QtUI/QtStatusWidget.cpp @@ -7,4 +7,8 @@ #include "QtStatusWidget.h" +#include <algorithm> +#include <boost/lambda/lambda.hpp> +#include <boost/lambda/bind.hpp> + #include <QBoxLayout> #include <QComboBox> @@ -24,8 +28,18 @@ #include "Swift/QtUI/QtSwiftUtil.h" #include <Swift/Controllers/StatusUtil.h> +#include <Swift/Controllers/StatusCache.h> + +namespace lambda = boost::lambda; namespace Swift { -QtStatusWidget::QtStatusWidget(QWidget *parent) : QWidget(parent), editCursor_(Qt::IBeamCursor), viewCursor_(Qt::PointingHandCursor) { +QtStatusWidget::QtStatusWidget(StatusCache* statusCache, QWidget *parent) : QWidget(parent), statusCache_(statusCache), editCursor_(Qt::IBeamCursor), viewCursor_(Qt::PointingHandCursor) { + allTypes_.push_back(StatusShow::Online); + allTypes_.push_back(StatusShow::FFC); + allTypes_.push_back(StatusShow::Away); + allTypes_.push_back(StatusShow::XA); + allTypes_.push_back(StatusShow::DND); + allTypes_.push_back(StatusShow::None); + isClicking_ = false; connecting_ = false; @@ -135,5 +149,20 @@ void QtStatusWidget::generateList() { item->setData(Qt::UserRole, QVariant(type)); } + std::vector<StatusCache::PreviousStatus> previousStatuses = statusCache_->getMatches(Q2PSTRING(text), 8); + foreach (StatusCache::PreviousStatus savedStatus, previousStatuses) { + if (savedStatus.first.empty() || std::find_if(allTypes_.begin(), allTypes_.end(), + savedStatus.second == lambda::_1 && savedStatus.first == lambda::bind(&statusShowTypeToFriendlyName, lambda::_1)) != allTypes_.end()) { + continue; + } + QListWidgetItem* item = new QListWidgetItem(P2QSTRING(savedStatus.first), menu_); + item->setIcon(icons_[savedStatus.second]); + item->setToolTip(item->text()); + item->setStatusTip(item->toolTip()); + item->setData(Qt::UserRole, QVariant(savedStatus.second)); + } foreach (StatusShow::Type type, icons_.keys()) { + if (Q2PSTRING(text) == statusShowTypeToFriendlyName(type)) { + continue; + } QListWidgetItem* item = new QListWidgetItem(P2QSTRING(statusShowTypeToFriendlyName(type)), menu_); item->setIcon(icons_[type]); @@ -142,6 +171,18 @@ void QtStatusWidget::generateList() { item->setData(Qt::UserRole, QVariant(type)); } + resizeMenu(); } +void QtStatusWidget::resizeMenu() { + int height = menu_->sizeHintForRow(0) * menu_->count(); + int marginLeft; + int marginTop; + int marginRight; + int marginBottom; + menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom); + height += marginTop + marginBottom; + + menu_->setGeometry(menu_->x(), menu_->y(), menu_->width(), height); +} void QtStatusWidget::handleClicked() { @@ -160,16 +201,9 @@ void QtStatusWidget::handleClicked() { x = screenWidth - width; } - std::vector<StatusShow::Type> types; - types.push_back(StatusShow::Online); - types.push_back(StatusShow::FFC); - types.push_back(StatusShow::Away); - types.push_back(StatusShow::XA); - types.push_back(StatusShow::DND); - types.push_back(StatusShow::None); - foreach (StatusShow::Type type, types) { - if (statusEdit_->text() == P2QSTRING(statusShowTypeToFriendlyName(type))) { + //foreach (StatusShow::Type type, allTypes_) { + // if (statusEdit_->text() == P2QSTRING(statusShowTypeToFriendlyName(type))) { statusEdit_->setText(""); - } - } + // } + //} generateList(); @@ -206,4 +240,5 @@ void QtStatusWidget::handleEditComplete() { viewMode(); emit onChangeStatusRequest(selectedStatusType_, statusText_); + statusCache_->addRecent(Q2PSTRING(statusText_), selectedStatusType_); } |