=== modified file 'mixxx/src/library/stardelegate.cpp' --- mixxx/src/library/stardelegate.cpp 2011-10-25 03:38:22 +0000 +++ mixxx/src/library/stardelegate.cpp 2012-05-23 22:09:24 +0000 @@ -23,6 +23,14 @@ #include "stareditor.h" #include "starrating.h" +StarDelegate::StarDelegate(QObject *pParent) : QStyledItemDelegate(pParent) { + + m_pTableView =qobject_cast (pParent); + connect(pParent, SIGNAL(entered(QModelIndex)), + this, SLOT(cellEntered(QModelIndex))); + m_isOneCellInEditMode = false; +} + /* * The function is invoked once for each item, represented by a QModelIndex object from the model. * If the data stored in the item is a StarRating, we paint it use a star editor for displaying; @@ -57,7 +65,8 @@ } StarRating starRating = qVariantValue(index.data()); - starRating.paint(painter, newOption.rect, newOption.palette, StarRating::ReadOnly); + starRating.paint(painter, newOption.rect, newOption.palette, StarRating::ReadOnly, + newOption.state & QStyle::State_Selected); } QSize StarDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const @@ -77,11 +86,11 @@ QWidget *StarDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,const QModelIndex &index) const { // Populate the correct colors based on the styling - //QStyleOptionViewItem newOption = option; - //initStyleOption(&newOption, index); - + QStyleOptionViewItem newOption = option; + initStyleOption(&newOption, index); if (qVariantCanConvert(index.data())) { - StarEditor *editor = new StarEditor(parent, option); + StarEditor *editor = new StarEditor(parent, option , + newOption.state & QStyle::State_Selected); connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return editor; @@ -120,3 +129,27 @@ emit commitData(editor); emit closeEditor(editor); } + +//cellEntered +void StarDelegate::cellEntered(const QModelIndex &index) +{ + //this slot is called if the mouse pointer enters ANY cell on + //the QTableView but the code should only be executed on a button + if(qVariantCanConvert(index.data())) + { + if(m_isOneCellInEditMode) + { + m_pTableView->closePersistentEditor(m_currentEditedCellIndex); + } + m_pTableView->openPersistentEditor(index); + m_isOneCellInEditMode = true; + m_currentEditedCellIndex = index; + } else { + if(m_isOneCellInEditMode) + { + m_isOneCellInEditMode = false; + m_pTableView->closePersistentEditor(m_currentEditedCellIndex); + } + } +} + === modified file 'mixxx/src/library/stardelegate.h' --- mixxx/src/library/stardelegate.h 2012-05-20 18:00:02 +0000 +++ mixxx/src/library/stardelegate.h 2012-05-23 22:09:24 +0000 @@ -20,6 +20,7 @@ #define STARDELEGATE_H #include +#include /* * When displaying data in a QListView, QTableView, or QTreeView, @@ -34,21 +35,28 @@ */ class StarDelegate : public QStyledItemDelegate { Q_OBJECT - public: - StarDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {} + +public: + StarDelegate(QObject *pParent = 0); /** reimplemented from QItemDelegate and is called whenever the view needs to repaint an item **/ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - /** eturns an item's preferred size **/ + /** returns an item's preferred size **/ QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; /** called when the user starts editing an item: **/ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,const QModelIndex &index) const; /** called when an editor is created to initialize it with data from the model: **/ void setEditorData(QWidget *editor, const QModelIndex &index) const; /** called when editing is finished, to commit data from the editor to the model: **/ - void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; private slots: void commitAndCloseEditor(); + void cellEntered(const QModelIndex &index); + +private: + QTableView *m_pTableView; + QPersistentModelIndex m_currentEditedCellIndex; + bool m_isOneCellInEditMode; }; #endif === modified file 'mixxx/src/library/stareditor.cpp' --- mixxx/src/library/stareditor.cpp 2010-10-19 04:14:18 +0000 +++ mixxx/src/library/stareditor.cpp 2012-05-23 22:09:24 +0000 @@ -35,12 +35,14 @@ * QWidget's auto-fill background feature to obtain an opaque background. * (Without the call, the view's background would shine through the editor.) */ -StarEditor::StarEditor(QWidget *parent, const QStyleOptionViewItem &option) +StarEditor::StarEditor(QWidget *parent, const QStyleOptionViewItem &option, + bool isSelected) : QWidget(parent) { setPalette(option.palette); setMouseTracking(true); setAutoFillBackground(true); + m_isSelected=isSelected; } QSize StarEditor::sizeHint() const @@ -54,7 +56,8 @@ void StarEditor::paintEvent(QPaintEvent *) { QPainter painter(this); - m_starRating.paint(&painter, rect(), palette(), StarRating::Editable); + m_starRating.paint(&painter, rect(), palette(), StarRating::Editable, + m_isSelected); } /* * In the mouse event handler, we call setStarCount() on === modified file 'mixxx/src/library/stareditor.h' --- mixxx/src/library/stareditor.h 2010-10-19 03:18:01 +0000 +++ mixxx/src/library/stareditor.h 2012-05-23 22:09:24 +0000 @@ -36,7 +36,8 @@ Q_OBJECT public: - StarEditor(QWidget *parent, const QStyleOptionViewItem& option); + StarEditor(QWidget *parent, const QStyleOptionViewItem& option, + bool isSelected); QSize sizeHint() const; void setStarRating(const StarRating &starRating) { @@ -56,6 +57,7 @@ int starAtPosition(int x); StarRating m_starRating; + bool m_isSelected; }; #endif === modified file 'mixxx/src/library/starrating.cpp' --- mixxx/src/library/starrating.cpp 2010-12-01 12:15:39 +0000 +++ mixxx/src/library/starrating.cpp 2012-05-23 22:09:24 +0000 @@ -44,7 +44,8 @@ /* * function paints the stars in this StarRating object on a paint device */ -void StarRating::paint(QPainter *painter, const QRect &rect, const QPalette &palette, EditMode mode) const +void StarRating::paint(QPainter *painter, const QRect &rect, const QPalette &palette, + EditMode mode, bool isSelected) const { painter->save(); @@ -54,7 +55,11 @@ // Workaround for painting issue. If we are editable, assume we are // selected, so use the highlight and hightlightedText colors. if (mode == Editable) { - painter->fillRect(rect, palette.highlight()); + if(isSelected){ + painter->fillRect(rect, palette.highlight()); + } else { + painter->fillRect(rect, palette.base()); + } painter->setBrush(palette.highlightedText()); } === modified file 'mixxx/src/library/starrating.h' --- mixxx/src/library/starrating.h 2010-10-19 03:18:01 +0000 +++ mixxx/src/library/starrating.h 2012-05-23 22:09:24 +0000 @@ -40,7 +40,8 @@ StarRating(int starCount = 1, int maxStarCount = 5); - void paint(QPainter *painter, const QRect &rect, const QPalette &palette, EditMode mode) const; + void paint(QPainter *painter, const QRect &rect, const QPalette &palette, EditMode mode, + bool isSelected) const; QSize sizeHint() const; int starCount() const { return m_myStarCount; } === modified file 'mixxx/src/widget/wlibrarytableview.cpp' --- mixxx/src/widget/wlibrarytableview.cpp 2012-05-20 18:00:02 +0000 +++ mixxx/src/widget/wlibrarytableview.cpp 2012-05-23 22:09:24 +0000 @@ -29,6 +29,7 @@ setShowGrid(false); setCornerButtonEnabled(false); setSortingEnabled(true); + setMouseTracking(true); //Work around a Qt bug that lets you make your columns so wide you //can't reach the divider to make them small again. setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); === modified file 'mixxx/src/widget/wtracktableview.cpp' --- mixxx/src/widget/wtracktableview.cpp 2012-05-20 20:19:37 +0000 +++ mixxx/src/widget/wtracktableview.cpp 2012-05-23 22:09:24 +0000 @@ -568,12 +568,24 @@ } void WTrackTableView::mouseMoveEvent(QMouseEvent* pEvent) { - Q_UNUSED(pEvent); - TrackModel* trackModel = getTrackModel(); + //emit this signal so that we know when a cell is entered by the mouse + QPoint bottomRight = pEvent->pos(); + QPersistentModelIndex index = indexAt(bottomRight); + if(index.isValid()){ + emit(entered(index)); + } + //only use this for drag and drop if the LeftButton is pressed + //we need to check for this because PreviewButtonDelegate activates + //mousetracking and this function is called everytime the mouse is moved + //-- kain88 May 2012 + if(pEvent->buttons()!=Qt::LeftButton){ + return; + } + TrackModel* trackModel = getTrackModel(); if (!trackModel) return; - - // Iterate over selected rows and append each item's location url to a list + // qDebug() << "MouseMoveEvent"; + // Iterate over selected rows and append each item's location url to a list. QList locationUrls; QModelIndexList indices = selectionModel()->selectedRows(); foreach (QModelIndex index, indices) { === modified file 'mixxx/src/widget/wtracktableview.h' --- mixxx/src/widget/wtracktableview.h 2012-05-08 15:37:16 +0000 +++ mixxx/src/widget/wtracktableview.h 2012-05-23 22:09:24 +0000 @@ -67,7 +67,10 @@ void lockBpm(bool lock); // Mouse move event, implemented to hide the text and show an icon instead - // when dragging + // when dragging, this overwrites the mouseMoveEvent from + //QAbstractItemModel if removing this function fixes strange + //behaviour for you, look there and check if our implementation is + //consistent with the original one void mouseMoveEvent(QMouseEvent *pEvent); // Returns the current TrackModel, or returns NULL if none is set.