From a23256347cc47605dd0660127052846427bc998d Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Mon, 10 Mar 2008 20:38:27 +0000 Subject: [PATCH] Purdificationings of the TopicWidget (no more colore codes). mIRC-Color backgrounds don't work though... no clue why *shrug* --- src/common/message.h | 5 +-- src/qtui/qtui.pri | 4 +-- src/qtui/topicbutton.cpp | 70 ++++++++++++++++++++++++++++++++++++++ src/qtui/topicbutton.h | 46 +++++++++++++++++++++++++ src/qtui/topicwidget.cpp | 36 ++++++++++++++++++-- src/qtui/topicwidget.h | 31 ++++++++++------- src/qtui/ui/topicwidget.ui | 25 ++++++++++---- version.inc | 4 +-- 8 files changed, 193 insertions(+), 28 deletions(-) create mode 100644 src/qtui/topicbutton.cpp create mode 100644 src/qtui/topicbutton.h diff --git a/src/common/message.h b/src/common/message.h index b262b97a..08c70c6f 100644 --- a/src/common/message.h +++ b/src/common/message.h @@ -79,6 +79,9 @@ public: //static QString formattedToHtml(const QString &); + /** Convert mIRC control codes to our own */ + static QString mircToInternal(QString); + void format(); private: @@ -92,8 +95,6 @@ private: QString _formattedTimestamp, _formattedSender, _formattedText; // cache - /** Convert mIRC control codes to our own */ - QString mircToInternal(QString); friend QDataStream &operator>>(QDataStream &in, Message &msg); }; diff --git a/src/qtui/qtui.pri b/src/qtui/qtui.pri index 096fc71a..e410de45 100644 --- a/src/qtui/qtui.pri +++ b/src/qtui/qtui.pri @@ -4,12 +4,12 @@ QT_MOD = core gui network SRCS += aboutdlg.cpp bufferwidget.cpp chatitem.cpp chatline.cpp chatline-old.cpp chatscene.cpp chatview.cpp chatwidget.cpp \ coreconfigwizard.cpp coreconnectdlg.cpp configwizard.cpp debugconsole.cpp inputwidget.cpp \ mainwin.cpp nicklistwidget.cpp qtui.cpp qtuisettings.cpp qtuistyle.cpp settingsdlg.cpp settingspagedlg.cpp \ - topicwidget.cpp verticaldock.cpp jumpkeyhandler.cpp + topicbutton.cpp topicwidget.cpp verticaldock.cpp jumpkeyhandler.cpp HDRS += aboutdlg.h bufferwidget.h chatitem.h chatline.h chatline-old.h chatscene.h chatview.h chatwidget.h \ coreconfigwizard.h configwizard.h debugconsole.h inputwidget.h \ coreconnectdlg.h mainwin.h nicklistwidget.h qtui.h qtuisettings.h qtuistyle.h settingsdlg.h settingspagedlg.h \ - topicwidget.h verticaldock.h jumpkeyhandler.h + topicbutton.h topicwidget.h verticaldock.h jumpkeyhandler.h FORMNAMES = aboutdlg.ui mainwin.ui coreaccounteditdlg.ui coreconnectdlg.ui bufferviewwidget.ui bufferwidget.ui nicklistwidget.ui settingsdlg.ui \ settingspagedlg.ui topicwidget.ui debugconsole.ui inputwidget.ui \ diff --git a/src/qtui/topicbutton.cpp b/src/qtui/topicbutton.cpp new file mode 100644 index 00000000..6ece9709 --- /dev/null +++ b/src/qtui/topicbutton.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (C) 2005/06 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "topicbutton.h" + + +#include + +#include +#include +#include +#include +#include + +#include "qtui.h" +#include "message.h" + +TopicButton::TopicButton(QWidget *parent) + : QAbstractButton(parent), + _sizeHint(QSize()) +{ +} + +void TopicButton::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + + QPainter painter(this); + QFontMetrics metrics(qApp->font()); + + QPoint topLeft = rect().topLeft(); + int height = sizeHint().height(); + int width = 0; + QRect drawRect; + QString textPart; + foreach(QTextLayout::FormatRange fr, styledText.formats) { + textPart = styledText.text.mid(fr.start, fr.length); + width = metrics.width(textPart); + drawRect = QRect(topLeft, QPoint(topLeft.x() + width, topLeft.y() + height)); + // qDebug() << drawRect << textPart << width << fr.format.background(); + painter.setPen(QPen(fr.format.foreground(), 0)); + painter.setBackground(fr.format.background()); // no clue why this doesnt work properly o_O + painter.drawText(drawRect, Qt::AlignLeft|Qt::TextSingleLine, textPart); + topLeft.setX(topLeft.x() + width); + } +} + +void TopicButton::setAndStyleText(const QString &text) { + styledText = QtUi::style()->styleString(Message::mircToInternal(text)); + setText(styledText.text); + + QFontMetrics metrics(qApp->font()); + _sizeHint = metrics.boundingRect(styledText.text).size(); +} diff --git a/src/qtui/topicbutton.h b/src/qtui/topicbutton.h new file mode 100644 index 00000000..c5fdc228 --- /dev/null +++ b/src/qtui/topicbutton.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2005/06 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef TOPICBUTTON_H +#define TOPICBUTTON_H + +#include +#include + +#include "uistyle.h" + +class TopicButton : public QAbstractButton { + Q_OBJECT + +public: + TopicButton(QWidget *parent = 0); + + void setAndStyleText(const QString &text); + +protected: + virtual void paintEvent(QPaintEvent *event); + virtual inline QSize sizeHint() const { return _sizeHint; } + +private: + UiStyle::StyledText styledText; + QSize _sizeHint; +}; + +#endif diff --git a/src/qtui/topicwidget.cpp b/src/qtui/topicwidget.cpp index 40e7ae8e..8adb0b6b 100644 --- a/src/qtui/topicwidget.cpp +++ b/src/qtui/topicwidget.cpp @@ -26,14 +26,46 @@ TopicWidget::TopicWidget(QWidget *parent) : QWidget(parent) { ui.setupUi(this); + ui.topicLineEdit->hide(); + ui.topicLineEdit->installEventFilter(this); + ui.topicButton->show(); } void TopicWidget::setTopic(const QString &newtopic) { + ui.topicButton->setAndStyleText(newtopic); ui.topicLineEdit->setText(newtopic); - ui.topicLineEdit->setCursorPosition(0); + switchPlain(); } void TopicWidget::on_topicLineEdit_returnPressed() { - ui.topicLineEdit->setCursorPosition(0); + switchPlain(); emit topicChanged(topic()); } + +void TopicWidget::on_topicButton_clicked() { + switchEditable(); +} + +void TopicWidget::switchEditable() { + ui.topicButton->hide(); + ui.topicLineEdit->show(); +} + +void TopicWidget::switchPlain() { + ui.topicLineEdit->hide(); + ui.topicButton->show(); +} + +bool TopicWidget::eventFilter(QObject *obj, QEvent *event) { + if(event->type() != QEvent::KeyPress) + return QObject::eventFilter(obj, event); + + QKeyEvent *keyEvent = static_cast(event); + + if(keyEvent->key() == Qt::Key_Escape) { + switchPlain(); + return true; + } + + return false; +} diff --git a/src/qtui/topicwidget.h b/src/qtui/topicwidget.h index f899a2ba..9492d847 100644 --- a/src/qtui/topicwidget.h +++ b/src/qtui/topicwidget.h @@ -29,20 +29,25 @@ class TopicWidget : public QWidget { Q_OBJECT Q_PROPERTY(QString topic READ topic WRITE setTopic STORED false) - public: - TopicWidget(QWidget *parent = 0); - - inline QString topic() const { return ui.topicLineEdit->text(); } - void setTopic(const QString &newtopic); - - signals: - void topicChanged(const QString &text); - - private slots: - void on_topicLineEdit_returnPressed(); +public: + TopicWidget(QWidget *parent = 0); + + inline QString topic() const { return ui.topicLineEdit->text(); } + void setTopic(const QString &newtopic); + + virtual bool eventFilter(QObject *obj, QEvent *event); + +signals: + void topicChanged(const QString &text); + +private slots: + void on_topicLineEdit_returnPressed(); + void on_topicButton_clicked(); + void switchEditable(); + void switchPlain(); - private: - Ui::TopicWidget ui; +private: + Ui::TopicWidget ui; }; diff --git a/src/qtui/ui/topicwidget.ui b/src/qtui/ui/topicwidget.ui index 5307a836..c73364ce 100644 --- a/src/qtui/ui/topicwidget.ui +++ b/src/qtui/ui/topicwidget.ui @@ -5,8 +5,8 @@ 0 0 - 558 - 29 + 458 + 28 @@ -32,20 +32,23 @@ - 0 + 2 - 0 + 2 - 0 + 2 - 0 + 2 + + + @@ -55,7 +58,7 @@ ... - :/22x22/actions/oxygen/22x22/actions/configure.png + @@ -67,6 +70,14 @@ + + + TopicButton + QWidget +
topicbutton.h
+ 1 +
+
diff --git a/version.inc b/version.inc index 58df021e..cb1fb4d0 100644 --- a/version.inc +++ b/version.inc @@ -4,8 +4,8 @@ { using namespace Global; quasselVersion = "0.2.0-alpha3-pre"; - quasselDate = "2008-03-09"; - quasselBuild = 622; + quasselDate = "2008-03-10"; + quasselBuild = 624; //! Minimum client build number the core needs clientBuildNeeded = 620; -- 2.20.1