Commit d2dcec63 authored by Scott Wheeler's avatar Scott Wheeler

First try at a "weighted" view for the column widths in JuK. There are

a number of outstanding issues, but I'm tired of having something working
and breaking it locally, so into CVS this goes.  Stuff that needs work:

*) manually resized columns will be resized on the next repaint
*) you can't get the old view back -- this will be configurable later
*) the balancing algorightm doesn't get things quite right
*) probably loads of other stuff that I just haven't noticed yet

(Yes, this is on the feature plan.)

svn path=/trunk/kdemultimedia/juk/; revision=248209
parent d18a6e03
This diff is collapsed.
......@@ -344,6 +344,10 @@ protected:
virtual void contentsDropEvent(QDropEvent *e);
virtual void showEvent(QShowEvent *e);
virtual bool acceptDrag(QDropEvent *e) const { return KURLDrag::canDecode(e); }
virtual void viewportPaintEvent(QPaintEvent *pe);
virtual void viewportResizeEvent(QResizeEvent *re);
void addColumn(const QString &label);
/**
* Here I'm using delayed setup of some things that aren't quite intuitive.
......@@ -462,6 +466,13 @@ private:
*/
int leftMostVisibleColumn() const;
void updateColumnWidths();
/**
* Build the column "weights" for the weighted width mode.
*/
void calculateColumnWeights();
/**
* This class is used internally to store settings that are shared by all
* of the playlists, such as column order. It is implemented as a singleton.
......@@ -514,19 +525,37 @@ private slots:
*/
void slotCreateGroup() { emit signalCreatePlaylist(selectedItems()); }
/**
* Tells the listview that the next time that it paints that the weighted
* column widths must be recalculated.
*/
void slotWidthDirty(int column);
private:
StringHash m_members;
int m_currentColumn;
int m_processed;
int m_rmbPasteID;
int m_rmbEditID;
int m_selectedCount;
bool m_allowDuplicates;
bool m_polished;
QValueList<int> m_widthDirty;
/**
* This is used to indicate if the list of visible items has changed (via a
* call to setVisibleItems()) while random play is playing.
* The average minimum widths of columns to be used in balancing calculations.
*/
static bool m_visibleChanged;
QValueVector<int> m_columnWeights;
PlaylistItemList m_randomList;
PlaylistItemList m_history;
PlaylistSearch m_search;
QString m_fileName;
PlaylistItem *m_lastSelected;
/**
* Used to store the text for inline editing before it is changed so that
......@@ -540,24 +569,19 @@ private:
* file name.
*/
QString m_playlistName;
QString m_fileName;
KPopupMenu *m_rmbMenu;
KPopupMenu *m_headerMenu;
KActionMenu *m_columnVisibleAction;
int m_rmbPasteID;
int m_rmbEditID;
int m_selectedCount;
PlaylistItem *m_lastSelected;
static PlaylistItem *m_playingItem;
/**
* This is used to indicate if the list of visible items has changed (via a
* call to setVisibleItems()) while random play is playing.
*/
static bool m_visibleChanged;
static int m_leftColumn;
PlaylistItemList m_randomList;
PlaylistSearch m_search;
bool m_polished;
static PlaylistItem *m_playingItem;
};
QDataStream &operator<<(QDataStream &s, const Playlist &p);
......
......@@ -130,6 +130,11 @@ void PlaylistItem::renameFile()
slotRefresh();
}
QValueVector<int> PlaylistItem::cachedWidths() const
{
return m_data->cachedWidths();
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistItem public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -270,7 +275,6 @@ void PlaylistItem::slotRefreshImpl()
// PlaylistItemData changes.
int offset = static_cast<Playlist *>(listView())->columnOffset();
setText(TrackColumn + offset, tag()->track());
setText(ArtistColumn + offset, tag()->artist());
......@@ -285,12 +289,15 @@ void PlaylistItem::slotRefreshImpl()
if(shortComment.length() > 50)
shortComment = shortComment.left(47) + "...";
setText(CommentColumn + offset, shortComment);
setText(CommentColumn + offset, shortComment);
int columns = listView()->columns();
int columns = lastColumn() + offset + 1;
m_data->setColumns(columns);
for(int i = 0; i < columns; i++)
for(int i = 0; i < columns; i++) {
m_data->setLocal8BitLower(i, text(i).lower().local8Bit());
m_data->setCachedWidth(i, width(listView()->fontMetrics(), listView(), i));
}
}
void PlaylistItem::slotTagGuessResults(const MusicBrainzQuery::TrackList &res)
......@@ -392,6 +399,12 @@ void PlaylistItem::Data::setFile(const QString &file)
refresh();
}
void PlaylistItem::Data::setColumns(int columns)
{
m_local8Bit.resize(columns);
m_cachedWidths.resize(columns, -1);
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistItem::Data protected methods
////////////////////////////////////////////////////////////////////////////////
......
......@@ -91,6 +91,12 @@ public:
void guessTagInfo(TagGuesser::Type type);
void renameFile();
/**
* The widths of items are cached when they're updated for us in computations
* in the "weighted" listview column width mode.
*/
QValueVector<int> cachedWidths() const;
public slots:
/**
* This just refreshes from the in memory data. This may seem pointless at
......@@ -184,10 +190,15 @@ public:
QString absFilePath() const { return m_absFileName; }
void setColumns(int columns) { m_local8Bit.resize(columns); }
void setColumns(int columns);
void setLocal8BitLower(int column, const QCString &value) { m_local8Bit[column] = value; }
QCString local8BitLower(int column) const { return m_local8Bit[column]; }
void setCachedWidth(int column, int value) { m_cachedWidths[column] = value; }
int cachedWidth(int column) const { return m_cachedWidths[column]; }
QValueVector<int> cachedWidths() const { return m_cachedWidths; }
protected:
/**
* Because we're trying to use this as a shared item, we want all access
......@@ -205,6 +216,7 @@ private:
Tag *m_dataTag;
QString m_absFileName;
QValueVector<QCString> m_local8Bit;
QValueVector<int> m_cachedWidths;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment