/* * Copyright (C) 2005, 2006 Liu Di * * Copyright (C) 2007 Wei Lian * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "header.h" #include "mainwindow.h" #include "sound.h" #include "config.h" #include "loadsave.h" #include "channel.h" #include "menubar.h" #include "tabwidget.h" #include "mystatusbar.h" #include "mylistitem.h" MainWindow::MainWindow (QWidget * parent, const char *name): QVBox (parent, name) { //menubar menubar = new MenuBar (this); ///channel row QHBox *hbox = new QHBox (this); ///button channel buttonchannel = new QToolButton (hbox); buttonchannel->setAutoRaise (true); buttonchannel->setUsesTextLabel (true); buttonchannel->setToggleButton (TRUE); buttonchannel->setTextLabel (tr ("Channel")); ///edit search editsearch = new QLineEdit ("", hbox); editsearch->setFocus (); connect (editsearch, SIGNAL (returnPressed ()), this, SLOT (onbuttonsearchclicked ())); ///button search buttonsearch = new QToolButton (hbox); buttonsearch->setTextLabel (tr ("Search")); buttonsearch->setAutoRaise (true); buttonsearch->setUsesTextLabel (true); connect (buttonsearch, SIGNAL (clicked ()), this, SLOT (onbuttonsearchclicked ())); ///button expand buttonexpand = new QToolButton (hbox); buttonexpand->setTextLabel (tr ("Expand")); buttonexpand->setAutoRaise (true); buttonexpand->setUsesTextLabel (true); connect (buttonexpand, SIGNAL (clicked ()), this, SLOT (onbuttonexpandclicked ())); ///sound slider sound = new Sound (this); slidersound = new QSlider (0, 100, 5, sound->volume (), QSlider::Horizontal, hbox); connect (slidersound, SIGNAL (valueChanged (int)), sound, SLOT (volume (int))); slidersound->setFixedWidth(55); ///timer for adjusting sound slider QTimer *timer = new QTimer (this); connect (timer, SIGNAL (timeout ()), this, SLOT (timerDone ())); timer->start (1000, FALSE); /////vboxconfig vboxconfig = new Config (this); ///row channel list channel = new Channel (this); connect (buttonchannel, SIGNAL (toggled (bool)), channel, SLOT (onButtonChannelToggled (bool))); ///row tab widget tabwidget = new TabWidget (this); ///row status bar statusbar = new MyStatusBar (this); ////load and save loadsave = new LoadSave (this); } MainWindow::~MainWindow () { delete loadsave; ///save width and height if (!isMaximized ()) { QSettings settings; settings.writeEntry ("/qsopcast/width", size ().width ()); settings.writeEntry ("/qsopcast/height", size ().height ()); } } void MainWindow::timerDone () { ///sound int value = sound->volume (); if (slidersound->value () != value) slidersound->setValue (value); } void MainWindow::onbuttonexpandclicked () { bool flag; if (buttonexpand->paletteForegroundColor () == Qt::black) { flag = TRUE; buttonexpand->setPaletteForegroundColor (Qt::blue); } else { flag = FALSE; buttonexpand->setPaletteForegroundColor (Qt::black); } QListViewItem *myChild = channel->firstChild (); while (myChild) { if (flag) myChild->setOpen (TRUE); else myChild->setOpen (FALSE); myChild = myChild->nextSibling (); } } void MainWindow::onbuttonsearchclicked () { if (channel->currentItem () == 0 || editsearch->text ().isEmpty ()) return; bool flagfirst = TRUE; QListViewItem *item, *childitem, *focusitem = 0; ////assign initial value if (channel->currentItem ()->depth () == 0) { item = channel->currentItem (); childitem = item->firstChild (); } else { childitem = channel->currentItem (); item = childitem->parent (); childitem = childitem->nextSibling (); } /////////find focus while (1) { while (childitem) { if (childitem->text (NAME_COLUMN). contains (editsearch->text (), false) && childitem->isEnabled ()) { channel->setCurrentItem (childitem); focusitem = childitem; flagfirst = FALSE; goto EXIT; } childitem = childitem->nextSibling (); } item = item->nextSibling (); if (!item) break; childitem = item->firstChild (); } EXIT:; ////set color and find first focus if having failed finding focus so far item = channel->firstChild (); while (item) { bool flag = FALSE; childitem = item->firstChild (); while (childitem) { if (childitem->text (NAME_COLUMN). contains (editsearch->text (), false) && childitem->isEnabled ()) { static_cast < MyListItem * >(childitem)->bcolor = Qt::yellow; childitem->repaint (); flag = TRUE; if (flagfirst == TRUE) { channel->setCurrentItem (childitem); focusitem = childitem; flagfirst = FALSE; } } else { static_cast < MyListItem * >(childitem)->bcolor = Qt::white; childitem->repaint (); } childitem = childitem->nextSibling (); } if (flag) { item->setOpen (TRUE); } else { item->setOpen (FALSE); } item = item->nextSibling (); } //////////////////scroll to the first found item if (focusitem == 0) return; int value = channel->itemPos (focusitem) - channel->height () / 2; channel->verticalScrollBar ()->setValue (value); }