Redesign the topic widget
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 21 Aug 2009 22:06:44 +0000 (00:06 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 21 Aug 2009 22:13:44 +0000 (00:13 +0200)
This replaces the old ugly hackish topicwidget by something cleaner. We now use a stacked widget to switch
between display and edit mode. In edit mode, we use a MultiLineEdit rather than a single QLineEdit.
Instead of doing voodooish resizing of the parent widget, we use proper sizeHints and sizePolicies that make
Qt's layout system actually work with this.

There are still some features missing though, notably clickable URLs and the clear button. Will
be implemented ASAP.

Closes #506, fixes #573, closes #608.

src/qtui/topicwidget.cpp
src/qtui/topicwidget.h
src/qtui/ui/topicwidget.ui

index cc66bd4..dbca69e 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "topicwidget.h"
 
 
 #include "topicwidget.h"
 
-#include <QDebug>
-
 #include "client.h"
 #include "iconloader.h"
 #include "networkmodel.h"
 #include "client.h"
 #include "iconloader.h"
 #include "networkmodel.h"
@@ -30,13 +28,9 @@ TopicWidget::TopicWidget(QWidget *parent)
   : AbstractItemView(parent)
 {
   ui.setupUi(this);
   : AbstractItemView(parent)
 {
   ui.setupUi(this);
-  ui.topicEditButton->setPixmap(BarIcon("edit-rename"));
+  ui.topicEditButton->setIcon(SmallIcon("edit-rename"));
 
 
-  ui.topicLineEdit->hide();
   ui.topicLineEdit->installEventFilter(this);
   ui.topicLineEdit->installEventFilter(this);
-  ui.topicLabel->show();
-  setContentsMargins(0,0,0,0);
-  parent->setMinimumHeight(layout()->sizeHint().height() + 2*qApp->style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin));
 }
 
 void TopicWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
 }
 
 void TopicWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
@@ -61,7 +55,7 @@ void TopicWidget::setTopic(const QString &newtopic) {
   switchPlain();
 }
 
   switchPlain();
 }
 
-void TopicWidget::on_topicLineEdit_returnPressed() {
+void TopicWidget::on_topicLineEdit_textEntered() {
   QModelIndex currentIdx = currentIndex();
   if(currentIdx.isValid() && currentIdx.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) {
     BufferInfo bufferInfo = currentIdx.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
   QModelIndex currentIdx = currentIndex();
   if(currentIdx.isValid() && currentIdx.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) {
     BufferInfo bufferInfo = currentIdx.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
@@ -78,26 +72,15 @@ void TopicWidget::on_topicEditButton_clicked() {
 }
 
 void TopicWidget::switchEditable() {
 }
 
 void TopicWidget::switchEditable() {
-  ui.topicLabel->hide();
-  ui.topicEditButton->hide();
-  ui.topicLineEdit->show();
+  ui.stackedWidget->setCurrentIndex(1);
   ui.topicLineEdit->setFocus();
   ui.topicLineEdit->setFocus();
-
-  setFixedHeight(layout()->sizeHint().height());
-  // Update the dock widget too, else it won't resize in all styles... FIXME try to sanitize this
-  qobject_cast<QWidget *>(parent())->setMinimumHeight(height() + 2*qApp->style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin));
-  qobject_cast<QWidget *>(parent())->adjustSize();
+  updateGeometry();
 }
 
 void TopicWidget::switchPlain() {
 }
 
 void TopicWidget::switchPlain() {
-  ui.topicLineEdit->hide();
-  ui.topicLabel->show();
-  ui.topicEditButton->show();
+  ui.stackedWidget->setCurrentIndex(0);
   ui.topicLineEdit->setText(_topic);
   ui.topicLineEdit->setText(_topic);
-  setFixedHeight(layout()->sizeHint().height());
-  // Update the dock widget too, else it won't resize in all styles... FIXME try to sanitize this
-  qobject_cast<QWidget *>(parent())->setMinimumHeight(height() + 2*qApp->style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin));
-  qobject_cast<QWidget *>(parent())->adjustSize();
+  updateGeometry();
 }
 
 // filter for the input widget to switch back to normal mode
 }
 
 // filter for the input widget to switch back to normal mode
index 666dd74..76e68f1 100644 (file)
@@ -18,8 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _TOPICWIDGET_H_
-#define _TOPICWIDGET_H_
+#ifndef TOPICWIDGET_H_
+#define TOPICWIDGET_H_
 
 #include "abstractitemview.h"
 
 
 #include "abstractitemview.h"
 
@@ -40,11 +40,11 @@ protected slots:
   virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
 
 private slots:
   virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
 
 private slots:
-  void on_topicLineEdit_returnPressed();
+  void on_topicLineEdit_textEntered();
   void on_topicEditButton_clicked();
   void switchEditable();
   void switchPlain();
   void on_topicEditButton_clicked();
   void switchEditable();
   void switchPlain();
-  
+
 private:
   Ui::TopicWidget ui;
 
 private:
   Ui::TopicWidget ui;
 
index 4610b01..0d5e8f2 100644 (file)
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>TopicWidget</class>
  <class>TopicWidget</class>
- <widget class="QWidget" name="TopicWidget" >
-  <property name="geometry" >
+ <widget class="QWidget" name="TopicWidget">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>644</width>
-    <height>35</height>
+    <width>643</width>
+    <height>27</height>
    </rect>
   </property>
    </rect>
   </property>
-  <property name="sizePolicy" >
-   <sizepolicy vsizetype="Preferred" hsizetype="MinimumExpanding" >
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
-  <property name="minimumSize" >
+  <property name="minimumSize">
    <size>
     <width>0</width>
     <height>0</height>
    </size>
   </property>
    <size>
     <width>0</width>
     <height>0</height>
    </size>
   </property>
-  <property name="baseSize" >
+  <property name="baseSize">
    <size>
     <width>0</width>
     <height>0</height>
    </size>
   </property>
    <size>
     <width>0</width>
     <height>0</height>
    </size>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>Form</string>
   </property>
    <string>Form</string>
   </property>
-  <layout class="QHBoxLayout" name="horizontalLayout>
-   <property name="sizeConstraint" >
-    <enum>QLayout::SetDefaultConstraint</enum>
+  <layout class="QHBoxLayout" name="horizontalLayout_2">
+   <property name="margin">
+    <number>0</number>
    </property>
    </property>
-   <property name="leftMargin" >
-    <number>4</number>
-   </property>
-   <property name="topMargin" >
-    <number>2</number>
-   </property>
-   <property name="rightMargin" >
-    <number>4</number>
-   </property>
-   <property name="bottomMargin" >
-    <number>2</number>
-   </property>
-   <item>
-    <widget class="TopicLabel" name="topicLabel" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Preferred" hsizetype="MinimumExpanding" >
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="frameShape" >
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow" >
-      <enum>QFrame::Plain</enum>
-     </property>
-    </widget>
-   </item>
    <item>
    <item>
-    <widget class="ClearableLineEdit" name="topicLineEdit" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
+    <widget class="ResizingStackedWidget" name="stackedWidget">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <property name="frame" >
-      <bool>true</bool>
-     </property>
-     <property name="alignment" >
-      <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="ClickableLabel" name="topicEditButton" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="text" >
-      <string/>
-     </property>
-     <property name="pixmap" >
-      <pixmap>:/22x22/actions/oxygen/22x22/actions/edit-clear.png</pixmap>
+     <property name="currentIndex">
+      <number>0</number>
      </property>
      </property>
+     <widget class="QWidget" name="page">
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Preferred" vsizetype="Ignored">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <property name="margin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="StyledLabel" name="topicLabel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="frameShape">
+          <enum>QFrame::StyledPanel</enum>
+         </property>
+         <property name="frameShadow">
+          <enum>QFrame::Plain</enum>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QToolButton" name="topicEditButton">
+         <property name="text">
+          <string>...</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="page_2">
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Preferred" vsizetype="Ignored">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <layout class="QVBoxLayout" name="verticalLayout_3">
+       <property name="margin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="MultiLineEdit" name="topicLineEdit">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
     </widget>
    </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
     </widget>
    </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
-   <class>ClearableLineEdit</class>
-   <extends>QLineEdit</extends>
-   <header location="global" >clearablelineedit.h</header>
+   <class>MultiLineEdit</class>
+   <extends>QTextEdit</extends>
+   <header>multilineedit.h</header>
   </customwidget>
   <customwidget>
   </customwidget>
   <customwidget>
-   <class>ClickableLabel</class>
-   <extends>QLabel</extends>
-   <header location="global" >clickablelabel.h</header>
+   <class>StyledLabel</class>
+   <extends>QFrame</extends>
+   <header>styledlabel.h</header>
+   <container>1</container>
   </customwidget>
   <customwidget>
   </customwidget>
   <customwidget>
-   <class>TopicLabel</class>
-   <extends>QFrame</extends>
-   <header location="global" >topiclabel.h</header>
+   <class>ResizingStackedWidget</class>
+   <extends>QStackedWidget</extends>
+   <header>resizingstackedwidget.h</header>
    <container>1</container>
   </customwidget>
  </customwidgets>
    <container>1</container>
   </customwidget>
  </customwidgets>