stationlistwidget.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2008  Tim Fechtner < urwald at users dot sourceforge dot net >
00003 
00004     This program is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU General Public License as
00006     published by the Free Software Foundation; either version 2 of
00007     the License or (at your option) version 3 or any later version
00008     accepted by the membership of KDE e.V. (or its successor approved
00009     by the membership of KDE e.V.), which shall act as a proxy
00010     defined in Section 14 of version 3 of the license.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "stationlistwidget.h"
00022 
00023 #include <QTimer>
00024 #include <QContextMenuEvent>
00025 #include <KLocale>
00026 #define AND  &&
00027 #define OR  ||
00028 #define NOT  !
00029 #define EQUAL  ==
00030 
00031 stationlistWidget::stationlistWidget(QWidget *parent, QPointer<QWidget> mainWindow)
00032   : QTableView(parent)
00033 {
00034   // variables
00035   QPointer<CustomizableHeaderView> theHorizontalHeader;
00036   int i;
00037 
00038   // code
00039   theHorizontalHeader = new CustomizableHeaderView(Qt::Horizontal);
00040   // this also deletes automatically the previously used (standard) QHeaderView object:
00041   setHorizontalHeader(theHorizontalHeader);
00042   theHorizontalHeader->setContextMenuTitle(
00043     i18nc("@title:menu Title of the context menu where you can change visibility of columns",
00044           "Columns"));
00045   /* We have to save the width of a column _befor_ it is hidden (after hiding,
00046   *  we wouln't be able to get the width anymore). */
00047   connect(theHorizontalHeader,
00048           SIGNAL(sectionAboutToBeHidden(int, Qt::Orientation)),
00049           this,
00050           SLOT(saveColumnSize(int)));
00051 
00052   setSelectionBehavior(QAbstractItemView::SelectRows);  // don't change this.
00053   // Much code relys on the assumption that only hole rows can be selected.
00054 
00055   setShowGrid(false);
00056 
00057   m_stationlistModel = new stationlistModel(this, mainWindow);
00058   setModel(m_stationlistModel);
00059 
00060   // restore column width
00061   for (i=0; i < m_stationlistModel->columnCount(); ++i) {
00062     setColumnHidden(
00063       i,
00064       !m_stationlistModel->columnInfo(stationlistModel::columnVisibility, i).toBool());
00065     setColumnWidth(
00066       i,
00067       m_stationlistModel->columnInfo(stationlistModel::columnWidth, i).toLongLong());
00068   };
00069 
00070   setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
00071   setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
00072 }
00073 
00074 stationlistWidget::~stationlistWidget()
00075 {
00076 }
00077 
00078 void stationlistWidget::saveAllColumnSizes()
00079 {
00080   // variables
00081   int i;
00082 
00083   // code
00084   for (i=0; i < m_stationlistModel->columnCount(); i++) {
00085     if (NOT isColumnHidden(i)) {
00086       saveColumnSize(i);
00087     };
00088     m_stationlistModel->columnInfo(stationlistModel::setColumnVisibility,
00089                                     i,
00090                                     -1,
00091                                     NOT isColumnHidden(i));
00092   };
00093 }
00094 
00095 void stationlistWidget::saveColumnSize(int column)
00096 {
00097   m_stationlistModel->columnInfo(stationlistModel::setColumnWidth,
00098                                   column,
00099                                   -1,
00100                                   columnWidth(column));
00101 }
00102 
00103 void stationlistWidget::record()
00104 {
00105   // variables
00106   int i;
00107   // initialized with a list of the selected rows (for column 0):
00108   QModelIndexList m_list = selectionModel()->selectedRows();
00109 
00110   // code
00111   for (i = 0; i < m_list.size(); ++i) {
00112     m_stationlistModel->record(m_list.at(i).row());
00113   };
00114 }
00115 
00116 void stationlistWidget::stopRecord()
00117 {
00118   // variables
00119   int i;
00120   // initialized with a list of the selected rows (for column 0):
00121   QModelIndexList m_list = selectionModel()->selectedRows();
00122 
00123   // code
00124   for (i = 0; i < m_list.size(); ++i) {
00125     m_stationlistModel->stopRecording(m_list.at(i).row());
00126   };
00127 }
00128 
00129 void stationlistWidget::selectionChanged(const QItemSelection & selected,
00130                                           const QItemSelection & deselected)
00131 {
00132   // call the original function from the base class
00133   QTableView::selectionChanged(selected, deselected);
00134 
00135   // code
00136   switch (selectionModel()->selectedRows().size()) {
00137     case 0:
00138       emit noneSelected(true);
00139       break;
00140     case 1:
00141       emit oneSelected(true);
00142       break;
00143     default:
00144       emit multipleSelected(true);
00145       break;
00146   };
00147 }
00148 
00149 void stationlistWidget::displayStreamSettings()
00150 {
00151   // variables
00152   // initialized with a list of the selected rows (for column 0):
00153   QModelIndexList m_list = selectionModel()->selectedRows();
00154 
00155   // code
00156   if (m_list.size() == 1) {
00157     m_stationlistModel->showConfigDialog(m_list.at(0).row());
00158   };
00159 }
00160 
00161 void stationlistWidget::deleteStation()
00162 {
00163   // variables
00164   QModelIndexList m_list;
00165 
00166   // code
00167   // initialized with a list of the selected rows (for column 0):
00168   m_list = selectionModel()->selectedRows();
00169   while (m_list.size() > 0) {
00170     m_stationlistModel->deleteStation(m_list.at(0).row());
00171     m_list = selectionModel()->selectedRows();
00172   };
00173 }
00174 
00175 void stationlistWidget::addNewStation()
00176 {
00177   m_stationlistModel->addNewStation();
00178   // TODO diese Station sollte dann auch selected werden.
00179 }
00180 
00181 void stationlistWidget::contextMenuEvent(QContextMenuEvent * e)
00182 {
00183   contextMenu.exec(e->globalPos());
00184 }
00185 
00186 QPointer<stationlistModel> stationlistWidget::stationlistmodel()
00187 {
00188   return m_stationlistModel;
00189 }
00190 
00191 bool stationlistWidget::queryClose()
00192 {
00193   saveAllColumnSizes();
00194   return stationlistmodel()->queryClose();
00195 }
00196 
00197 void stationlistWidget::saveProperties(KConfigGroup & m_configGroup)
00198 {
00199   saveAllColumnSizes();
00200   stationlistmodel()->saveProperties(m_configGroup);
00201 }
00202 
00203 void stationlistWidget::readProperties(const KConfigGroup & m_configGroup)
00204 {
00205   stationlistmodel()->readProperties(m_configGroup);
00206 }

Generated on Sat May 2 10:43:44 2009 for kradioripper by  doxygen 1.5.6