view/main.cpp
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sun, 24 Oct 2010 20:55:54 +0200
changeset 149 5acf77b9b7a0
parent 81 6cfca66d2f01
permissions -rw-r--r--
working Makefile rules O_O committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
 * Q3ListView Demo
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 */
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
#include <QApplication>
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include "view.hpp"
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
void TView::down ()
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
{
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
    Q3ListViewItem *item = listView->selectedItem ();
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
    Q3ListViewItem *cur, *next;
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
    if ((cur = item) == NULL)
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
        return;
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
    if ((next = cur->itemBelow ()) == NULL)
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
        return;
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
    /*
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
     * move cur after next
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
     */
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
    cur->moveItem (next);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
    /*
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
     * highlight the next item
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
     */
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
    listView->setSelected (cur, true);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
}
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
void TView::up ()
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
{
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
    Q3ListViewItem *item = listView->selectedItem ();
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
    Q3ListViewItem *cur, *next;
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
    if ((cur = item) == NULL)
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
        return;
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
    if ((next = cur->itemAbove ()) == NULL)
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
        return;
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
    /*
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
     * move next after cur
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
     */
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
    next->moveItem (cur);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
    /*
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
     * highlight the next item
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
     */
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    47
    listView->setSelected (cur, true);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
}
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
TView::TView (QWidget * parent)
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
:  QDialog (parent, 0)
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
{
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
    Q3ListViewItem *item = NULL;
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
    setupUi (this);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
    listView->addColumn ("Picture");
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
    listView->addColumn ("Artist");
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
    listView->addColumn ("Price");
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
    item = new Q3ListViewItem (listView, item, "Mona Lisa", "Leonardo da Vinci", "35.000.000");
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
    item = new Q3ListViewItem (listView, item, "The Thinker", "Auguste Rodin", "12.850.000");
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
    item = new Q3ListViewItem (listView, item, "Starnight", "Vincent van Gogh", "435.000");
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
    item = new Q3ListViewItem (listView, item, "The Kiss", "Gustav Klimt", "125.000");
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    65
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    66
    connect (upButton, SIGNAL (clicked ()), this, SLOT (up ()));
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    67
    connect (downButton, SIGNAL (clicked ()), this, SLOT (down ()));
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    69
    item = listView->firstChild ();
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    70
    listView->setSelected (item, true);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    71
    listView->setSorting (-1, FALSE);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
}
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    74
TView::~TView ()
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    75
{
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    76
    listView->clear ();
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    77
}
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    78
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    79
int main (int argc, char **argv)
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    80
{
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    81
    QApplication app (argc, argv);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    82
    TView view;
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    83
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    84
    app.setMainWidget (&view);
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    85
    view.show ();
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    86
    return app.exec ();
6cfca66d2f01 A simple QT Demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    87
}