Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/widget/wlibrarytableview.cpp

Go to the documentation of this file.
00001 // wlibrarytableview.cpp
00002 // Created 10/19/2009 by RJ Ryan (rryan@mit.edu)
00003 
00004 #include <QHeaderView>
00005 #include <QPalette>
00006 #include <QScrollBar>
00007 
00008 #include "widget/wwidget.h"
00009 #include "widget/wskincolor.h"
00010 #include "widget/wlibrarytableview.h"
00011 #include "../library/stardelegate.h"
00012 
00013 WLibraryTableView::WLibraryTableView(QWidget* parent,
00014                                      ConfigObject<ConfigValue>* pConfig,
00015                                      ConfigKey vScrollBarPosKey)
00016         : QTableView(parent),
00017           m_pConfig(pConfig),
00018           m_vScrollBarPosKey(vScrollBarPosKey) {
00019 
00020     // Setup properties for table
00021 
00022     // Editing starts when clicking on an already selected item.
00023     setEditTriggers(QAbstractItemView::SelectedClicked);
00024 
00025     // This is to support rating of tracks
00026     setItemDelegate(new StarDelegate(this));
00027 
00028     //Enable selection by rows and extended selection (ctrl/shift click)
00029     setSelectionBehavior(QAbstractItemView::SelectRows);
00030     setSelectionMode(QAbstractItemView::ExtendedSelection);
00031 
00032     setWordWrap(false);
00033     setShowGrid(false);
00034     setCornerButtonEnabled(false);
00035     setSortingEnabled(true);
00036     //Work around a Qt bug that lets you make your columns so wide you
00037     //can't reach the divider to make them small again.
00038     setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
00039 
00040     verticalHeader()->hide();
00041     verticalHeader()->setDefaultSectionSize(20);
00042     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
00043     setAlternatingRowColors(true);
00044 
00045     loadVScrollBarPosState();
00046 
00047     setTabKeyNavigation(false);
00048 }
00049 
00050 WLibraryTableView::~WLibraryTableView() {
00051     qDebug() << "~WLibraryTableView";
00052     saveVScrollBarPosState();
00053 }
00054 
00055 void WLibraryTableView::setup(QDomNode node) {
00056 }
00057 
00058 void WLibraryTableView::loadVScrollBarPosState() {
00059     // TODO(rryan) I'm not sure I understand the value in saving the v-scrollbar
00060     // position across restarts of Mixxx. Now that we have different views for
00061     // each mode, the views should just maintain their scrollbar position when
00062     // you switch views. We should discuss this.
00063     m_iSavedVScrollBarPos = m_pConfig->getValueString(m_vScrollBarPosKey).toInt();
00064 }
00065 
00066 void WLibraryTableView::restoreVScrollBarPos() {
00067     //Restore the scrollbar's position (scroll to that spot)
00068     //when the search has been cleared
00069     verticalScrollBar()->setValue(m_iSavedVScrollBarPos);
00070 }
00071 
00072 void WLibraryTableView::saveVScrollBarPos() {
00073     //Save the scrollbar's position so we can return here after
00074     //a search is cleared.
00075     m_iSavedVScrollBarPos = verticalScrollBar()->value();
00076 }
00077 
00078 
00079 void WLibraryTableView::saveVScrollBarPosState() {
00080     //Save the vertical scrollbar position.
00081     int scrollbarPosition = verticalScrollBar()->value();
00082     m_pConfig->set(m_vScrollBarPosKey, ConfigValue(scrollbarPosition));
00083 }
00084 
00085 void WLibraryTableView::moveSelection(int delta) {
00086     QAbstractItemModel* pModel = model();
00087 
00088     if (pModel == NULL) {
00089         return;
00090     }
00091 
00092     while(delta != 0) {
00093         // TODO(rryan) what happens if there is nothing selected?
00094         QModelIndex current = currentIndex();
00095         if(delta > 0) {
00096             // i is positive, so we want to move the highlight down
00097             int row = current.row();
00098             if (row + 1 < pModel->rowCount())
00099                 selectRow(row + 1);
00100 
00101             delta--;
00102         } else {
00103             // i is negative, so we want to move the highlight up
00104             int row = current.row();
00105             if (row - 1 >= 0)
00106                 selectRow(row - 1);
00107 
00108             delta++;
00109         }
00110     }
00111 }
00112 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines