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