summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-08-16 13:13:20 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-08-16 13:13:20 (GMT)
commit6d64d22bdc18a8b4d3ef1ae7087f657de6c9abd9 (patch)
tree5994c7ee6b89bb6a1d24d849cb21ee3fe2f48191 /Swift
parent2ef0428c1f9559454654546f3cce32155cf5409d (diff)
downloadswift-contrib-6d64d22bdc18a8b4d3ef1ae7087f657de6c9abd9.zip
swift-contrib-6d64d22bdc18a8b4d3ef1ae7087f657de6c9abd9.tar.bz2
MeView collapsing.
Qt's peculiarities with which mouse events get passed where are evident here: clicking the toolbar collapses/expands, while if you're clicking the label, it has to be a doubleclick to collapse or expand.
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/QtRosterHeader.cpp43
-rw-r--r--Swift/QtUI/QtRosterHeader.h6
2 files changed, 42 insertions, 7 deletions
diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp
index 86e64ca..9b5410b 100644
--- a/Swift/QtUI/QtRosterHeader.cpp
+++ b/Swift/QtUI/QtRosterHeader.cpp
@@ -5,6 +5,7 @@
#include <QIcon>
#include <QSizePolicy>
#include <qdebug.h>
+#include <QMouseEvent>
#include "QtStatusWidget.h"
@@ -20,7 +21,7 @@ QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) {
statusWidget_ = new QtStatusWidget(this);
toolBar_->addWidget(statusWidget_);
- statusWidget_->resize(50, statusWidget_->height());
+ statusWidget_->setMaximumWidth(60);
connect(statusWidget_, SIGNAL(onChangeStatusRequest(StatusShow::Type)), this, SLOT(handleChangeStatusRequest(StatusShow::Type)));
nameLabel_ = new QLabel(this);
@@ -28,26 +29,54 @@ QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) {
toolBar_->addWidget(nameLabel_);
//nameLabel_->setMaximumWidth(width() - 5 - statusWidget_->width());
- QHBoxLayout* expandedLayout = new QHBoxLayout();
- expandedLayout->setContentsMargins(5,5,5,5);
- expandedLayout->setSpacing(11);
+ expandedLayout_ = new QHBoxLayout();
+ expandedLayout_->setContentsMargins(0,0,0,0);
+ expandedLayout_->setSpacing(0);
avatarLabel_ = new QLabel(this);
setAvatar(":/icons/avatar.png");
- expandedLayout->addWidget(avatarLabel_);
+ expandedLayout_->addWidget(avatarLabel_);
statusEdit_ = new QTextEdit(this);
- expandedLayout->addWidget(statusEdit_);
+ expandedLayout_->addWidget(statusEdit_);
statusEdit_->resize(statusEdit_->width(), 64);
statusEdit_->setAcceptRichText(false);
statusEdit_->setReadOnly(false);
setStatusText("");
- vLayout->addLayout(expandedLayout);
+ vLayout->addLayout(expandedLayout_);
+ expanded_ = false;
+ avatarLabel_->hide();
+ statusEdit_->hide();
setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
}
+void QtRosterHeader::mousePressEvent(QMouseEvent* event) {
+ if (nameLabel_->underMouse() || toolBar_->underMouse() && !statusWidget_->underMouse()) {
+ toggleExpanded();
+ event->accept();
+ } else {
+ event->ignore();
+ }
+
+}
+
+void QtRosterHeader::toggleExpanded() {
+ expanded_ = !expanded_;
+ if (expanded_) {
+ expandedLayout_->setContentsMargins(5,5,5,5);
+ expandedLayout_->setSpacing(11);
+ avatarLabel_->show();
+ statusEdit_->show();
+ } else {
+ expandedLayout_->setContentsMargins(0,0,0,0);
+ expandedLayout_->setSpacing(0);
+ avatarLabel_->hide();
+ statusEdit_->hide();
+ }
+}
+
void QtRosterHeader::handleChangeStatusRequest(StatusShow::Type type) {
Q_UNUSED(type);
emitStatus();
diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h
index ae510ee..66c9333 100644
--- a/Swift/QtUI/QtRosterHeader.h
+++ b/Swift/QtUI/QtRosterHeader.h
@@ -10,6 +10,8 @@
#include "Swiften/Base/String.h"
#include "Swiften/Elements/StatusShow.h"
+class QHBoxLayout;
+
namespace Swift {
class QtStatusWidget;
@@ -28,13 +30,17 @@ namespace Swift {
void handleChangeStatusRequest(StatusShow::Type type);
protected:
virtual void resizeEvent(QResizeEvent* event);
+ virtual void mousePressEvent(QMouseEvent* event);
private:
void resizeNameLabel();
+ void toggleExpanded();
QString name_;
QLabel* avatarLabel_;
QLabel* nameLabel_;
QTextEdit* statusEdit_;
QToolBar* toolBar_;
QtStatusWidget* statusWidget_;
+ QHBoxLayout* expandedLayout_;
+ bool expanded_;
};
}