A simple QT Demo
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:51:15 +0200
changeset 81 6cfca66d2f01
parent 80 5d7057a1b202
child 82 7ff8fc49cce4
A simple QT Demo I needed a playground to become familiar with the teamgit ui committer: Markus Bröker <mbroeker@largo.homelinux.org>
view/.gitignore
view/main.cpp
view/maindialog.ui
view/view.hpp
view/view.pro
new file mode 100644
--- /dev/null
+++ b/view/.gitignore
@@ -0,0 +1,3 @@
+Makefile
+moc_view.cpp
+ui_maindialog.h
new file mode 100644
--- /dev/null
+++ b/view/main.cpp
@@ -0,0 +1,87 @@
+/**
+ * Q3ListView Demo
+ */
+
+#include <QApplication>
+#include "view.hpp"
+
+void TView::down ()
+{
+    Q3ListViewItem *item = listView->selectedItem ();
+    Q3ListViewItem *cur, *next;
+
+    if ((cur = item) == NULL)
+        return;
+    if ((next = cur->itemBelow ()) == NULL)
+        return;
+
+    /*
+     * move cur after next
+     */
+    cur->moveItem (next);
+
+    /*
+     * highlight the next item
+     */
+    listView->setSelected (cur, true);
+}
+
+void TView::up ()
+{
+    Q3ListViewItem *item = listView->selectedItem ();
+    Q3ListViewItem *cur, *next;
+
+    if ((cur = item) == NULL)
+        return;
+    if ((next = cur->itemAbove ()) == NULL)
+        return;
+
+    /*
+     * move next after cur
+     */
+    next->moveItem (cur);
+
+    /*
+     * highlight the next item
+     */
+    listView->setSelected (cur, true);
+}
+
+TView::TView (QWidget * parent)
+:  QDialog (parent, 0)
+{
+    Q3ListViewItem *item = NULL;
+
+    setupUi (this);
+
+    listView->addColumn ("Picture");
+    listView->addColumn ("Artist");
+    listView->addColumn ("Price");
+
+    item = new Q3ListViewItem (listView, item, "Mona Lisa", "Leonardo da Vinci", "35.000.000");
+    item = new Q3ListViewItem (listView, item, "The Thinker", "Auguste Rodin", "12.850.000");
+    item = new Q3ListViewItem (listView, item, "Starnight", "Vincent van Gogh", "435.000");
+    item = new Q3ListViewItem (listView, item, "The Kiss", "Gustav Klimt", "125.000");
+
+    connect (upButton, SIGNAL (clicked ()), this, SLOT (up ()));
+    connect (downButton, SIGNAL (clicked ()), this, SLOT (down ()));
+
+    item = listView->firstChild ();
+    listView->setSelected (item, true);
+    listView->setSorting (-1, FALSE);
+}
+
+TView::~TView ()
+{
+    listView->clear ();
+}
+
+int main (int argc, char **argv)
+{
+    QApplication app (argc, argv);
+    TView view;
+
+    app.setMainWidget (&view);
+    view.show ();
+    return app.exec ();
+}
new file mode 100644
--- /dev/null
+++ b/view/maindialog.ui
@@ -0,0 +1,95 @@
+<ui version="4.0" >
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>493</width>
+    <height>389</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_3" >
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout" >
+     <item>
+      <widget class="Q3ListView" name="listView" />
+     </item>
+     <item>
+      <layout class="QVBoxLayout" name="verticalLayout_2" >
+       <item>
+        <widget class="QPushButton" name="upButton" >
+         <property name="text" >
+          <string>up</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="downButton" >
+         <property name="text" >
+          <string>down</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons" >
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>Q3ListView</class>
+   <extends>Q3Frame</extends>
+   <header>q3listview.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>Dialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>Dialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
new file mode 100644
--- /dev/null
+++ b/view/view.hpp
@@ -0,0 +1,20 @@
+#ifndef VIEW_HPP
+#define VIEW_HPP
+
+#include "ui_maindialog.h"
+
+class TView : public QDialog, Ui_Dialog {
+  Q_OBJECT
+    public:
+      TView (QWidget * parent = 0);
+      virtual ~TView ();
+
+    protected slots:
+      void up ();
+      void down ();
+
+  private:
+};
+
+#endif
+
new file mode 100644
--- /dev/null
+++ b/view/view.pro
@@ -0,0 +1,14 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Mi Jan 7 01:07:54 2009
+######################################################################
+
+TEMPLATE = app
+QT = gui qt3support
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+HEADERS += view.hpp
+FORMS += maindialog.ui
+SOURCES += main.cpp