Purdificationings of the TopicWidget (no more colore codes).
authorMarcus Eggenberger <egs@quassel-irc.org>
Mon, 10 Mar 2008 20:38:27 +0000 (20:38 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Mon, 10 Mar 2008 20:38:27 +0000 (20:38 +0000)
mIRC-Color backgrounds don't work though... no clue why *shrug*

src/common/message.h
src/qtui/qtui.pri
src/qtui/topicbutton.cpp [new file with mode: 0644]
src/qtui/topicbutton.h [new file with mode: 0644]
src/qtui/topicwidget.cpp
src/qtui/topicwidget.h
src/qtui/ui/topicwidget.ui
version.inc

index b262b97..08c70c6 100644 (file)
@@ -79,6 +79,9 @@ public:
 
   //static QString formattedToHtml(const QString &);
 
 
   //static QString formattedToHtml(const QString &);
 
+  /** Convert mIRC control codes to our own */
+  static QString mircToInternal(QString);
+
   void format();
 
 private:
   void format();
 
 private:
@@ -92,8 +95,6 @@ private:
 
   QString _formattedTimestamp, _formattedSender, _formattedText; // cache
 
 
   QString _formattedTimestamp, _formattedSender, _formattedText; // cache
 
-  /** Convert mIRC control codes to our own */
-  QString mircToInternal(QString);
 
   friend QDataStream &operator>>(QDataStream &in, Message &msg);
 };
 
   friend QDataStream &operator>>(QDataStream &in, Message &msg);
 };
index 096fc71..e410de4 100644 (file)
@@ -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 \
 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 \
 
 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 \
 
 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 (file)
index 0000000..6ece970
--- /dev/null
@@ -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 <QDebug>
+
+#include <QApplication>
+#include <QPainter>
+#include <QHBoxLayout>
+#include <QFont>
+#include <QFontMetrics>
+
+#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 (file)
index 0000000..c5fdc22
--- /dev/null
@@ -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 <QSize>
+#include <QAbstractButton>
+
+#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
index 40e7ae8..8adb0b6 100644 (file)
@@ -26,14 +26,46 @@ TopicWidget::TopicWidget(QWidget *parent)
   : QWidget(parent)
 {
   ui.setupUi(this);
   : QWidget(parent)
 {
   ui.setupUi(this);
+  ui.topicLineEdit->hide();
+  ui.topicLineEdit->installEventFilter(this);
+  ui.topicButton->show();
 }
 
 void TopicWidget::setTopic(const QString &newtopic) {
 }
 
 void TopicWidget::setTopic(const QString &newtopic) {
+  ui.topicButton->setAndStyleText(newtopic);
   ui.topicLineEdit->setText(newtopic);
   ui.topicLineEdit->setText(newtopic);
-  ui.topicLineEdit->setCursorPosition(0);
+  switchPlain();
 }
 
 void TopicWidget::on_topicLineEdit_returnPressed() {
 }
 
 void TopicWidget::on_topicLineEdit_returnPressed() {
-  ui.topicLineEdit->setCursorPosition(0);
+  switchPlain();
   emit topicChanged(topic());
 }
   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<QKeyEvent *>(event);
+
+  if(keyEvent->key() == Qt::Key_Escape) {
+    switchPlain();
+    return true;
+  }
+  
+  return false;
+}
index f899a2b..9492d84 100644 (file)
@@ -29,20 +29,25 @@ class TopicWidget : public QWidget {
   Q_OBJECT
   Q_PROPERTY(QString topic READ topic WRITE setTopic STORED false)
 
   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;
 };
 
 
 };
 
 
index 5307a83..c73364c 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>558</width>
-    <height>29</height>
+    <width>458</width>
+    <height>28</height>
    </rect>
   </property>
   <property name="sizePolicy" >
    </rect>
   </property>
   <property name="sizePolicy" >
   </property>
   <layout class="QHBoxLayout" >
    <property name="leftMargin" >
   </property>
   <layout class="QHBoxLayout" >
    <property name="leftMargin" >
-    <number>0</number>
+    <number>2</number>
    </property>
    <property name="topMargin" >
    </property>
    <property name="topMargin" >
-    <number>0</number>
+    <number>2</number>
    </property>
    <property name="rightMargin" >
    </property>
    <property name="rightMargin" >
-    <number>0</number>
+    <number>2</number>
    </property>
    <property name="bottomMargin" >
    </property>
    <property name="bottomMargin" >
-    <number>0</number>
+    <number>2</number>
    </property>
    <item>
     <widget class="QLineEdit" name="topicLineEdit" />
    </item>
    </property>
    <item>
     <widget class="QLineEdit" name="topicLineEdit" />
    </item>
+   <item>
+    <widget class="TopicButton" native="1" name="topicButton" />
+   </item>
    <item>
     <widget class="QToolButton" name="topicEditButton" >
      <property name="enabled" >
    <item>
     <widget class="QToolButton" name="topicEditButton" >
      <property name="enabled" >
@@ -55,7 +58,7 @@
       <string>...</string>
      </property>
      <property name="icon" >
       <string>...</string>
      </property>
      <property name="icon" >
-      <iconset resource="../../icons/icons.qrc" >:/22x22/actions/oxygen/22x22/actions/configure.png</iconset>
+      <iconset/>
      </property>
      <property name="iconSize" >
       <size>
      </property>
      <property name="iconSize" >
       <size>
    </item>
   </layout>
  </widget>
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>TopicButton</class>
+   <extends>QWidget</extends>
+   <header location="global" >topicbutton.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <resources>
   <include location="../../icons/icons.qrc" />
  </resources>
  <resources>
   <include location="../../icons/icons.qrc" />
  </resources>
index 58df021..cb1fb4d 100644 (file)
@@ -4,8 +4,8 @@
 { using namespace Global;
 
   quasselVersion = "0.2.0-alpha3-pre";
 { 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;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 620;