view/main.cpp
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 19 Nov 2010 14:49:47 +0100
changeset 159 44823a881da1
parent 81 6cfca66d2f01
permissions -rw-r--r--
set default socket options: IPV6_V6ONLY, SO_REUSEADDR committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * 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 ();
}