Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4c3e3a5b authored by Scott Wheeler's avatar Scott Wheeler

Allow the user to resize the columns. This still feels a little awkward

since the column sizer will override settings to fill the remaining width,
but again it's a step in the right direction.  It's still not possible to
get the "full width" mode that was the default before back, but again --
another day...

svn path=/trunk/kdemultimedia/juk/; revision=248454
parent e046f489
......@@ -217,6 +217,7 @@ Playlist::Playlist(QWidget *parent, const QString &name) :
m_allowDuplicates(false),
m_polished(false),
m_disableColumnWidthUpdates(true),
m_widthsDirty(true),
m_lastSelected(0),
m_playlistName(name),
m_rmbMenu(0)
......@@ -230,6 +231,7 @@ Playlist::Playlist(const QFileInfo &playlistFile, QWidget *parent, const QString
m_allowDuplicates(false),
m_polished(false),
m_disableColumnWidthUpdates(true),
m_widthsDirty(true),
m_lastSelected(0),
m_fileName(playlistFile.absFilePath()),
m_rmbMenu(0)
......@@ -558,19 +560,19 @@ void Playlist::slotReload()
loadFile(m_fileName, fileInfo);
}
void Playlist::slotWidthDirty(int column)
void Playlist::slotWeightDirty(int column)
{
if(column < 0) {
m_widthDirty.clear();
m_weightDirty.clear();
for(int i = 0; i < columns(); i++) {
if(isColumnVisible(i))
m_widthDirty.append(i);
m_weightDirty.append(i);
}
return;
}
if(m_widthDirty.find(column) == m_widthDirty.end())
m_widthDirty.append(column);
if(m_weightDirty.find(column) == m_weightDirty.end())
m_weightDirty.append(column);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -649,9 +651,22 @@ void Playlist::decode(QMimeSource *s, PlaylistItem *after)
bool Playlist::eventFilter(QObject *watched, QEvent *e)
{
if(watched == header()) {
if(e->type() == QEvent::MouseButtonPress) {
if(static_cast<QMouseEvent*>(e)->button() == RightButton)
switch(e->type()) {
case QEvent::MouseButtonPress:
{
if(static_cast<QMouseEvent *>(e)->button() == RightButton)
m_headerMenu->popup(QCursor::pos());
break;
}
case QEvent::MouseButtonRelease:
{
if(m_widthsDirty)
QTimer::singleShot(0, this, SLOT(slotUpdateColumnWidths()));
break;
}
default:
break;
}
}
......@@ -711,9 +726,9 @@ void Playlist::viewportPaintEvent(QPaintEvent *pe)
{
// If there are columns that need to be updated, well, update them.
if(!m_widthDirty.isEmpty()) {
if(!m_weightDirty.isEmpty()) {
calculateColumnWeights();
updateColumnWidths();
slotUpdateColumnWidths();
}
KListView::viewportPaintEvent(pe);
......@@ -725,14 +740,14 @@ void Playlist::viewportResizeEvent(QResizeEvent *re)
// widths.
if(re->size().width() != re->oldSize().width())
updateColumnWidths();
slotUpdateColumnWidths();
KListView::viewportResizeEvent(re);
}
void Playlist::addColumn(const QString &label)
{
slotWidthDirty(columns());
slotWeightDirty(columns());
KListView::addColumn(label, 30);
}
......@@ -762,7 +777,7 @@ void Playlist::hideColumn(int c)
m_leftColumn = leftMostVisibleColumn();
}
updateColumnWidths();
slotUpdateColumnWidths();
triggerUpdate();
emit signalVisibleColumnsChanged();
}
......@@ -784,7 +799,7 @@ void Playlist::showColumn(int c)
m_leftColumn = leftMostVisibleColumn();
}
updateColumnWidths();
slotUpdateColumnWidths();
triggerUpdate();
emit signalVisibleColumnsChanged();
}
......@@ -804,7 +819,6 @@ QString Playlist::resolveSymLinks(const QFileInfo &file) // static
return QFile::decodeName(real);
else
return file.filePath();
}
void Playlist::polish()
......@@ -842,6 +856,8 @@ void Playlist::polish()
setShowSortIndicator(true);
setDropVisualizer(true);
m_columnFixedWidths.resize(columns(), 0);
//////////////////////////////////////////////////
// setup header RMB menu
//////////////////////////////////////////////////
......@@ -867,6 +883,9 @@ void Playlist::polish()
connect(this, SIGNAL(itemRenamed(QListViewItem *, const QString &, int)),
this, SLOT(slotApplyModification(QListViewItem *, const QString &, int)));
connect(header(), SIGNAL(sizeChange(int, int, int)),
this, SLOT(slotColumnSizeChanged(int, int, int)));
setHScrollBarMode(AlwaysOff);
setAcceptDrops(true);
......@@ -957,7 +976,47 @@ int Playlist::leftMostVisibleColumn() const
return header()->mapToSection(i);
}
void Playlist::updateColumnWidths()
void Playlist::calculateColumnWeights()
{
if(m_disableColumnWidthUpdates)
return;
PlaylistItemList l = items();
QValueListConstIterator<int> columnIt;
QValueVector<double> averageWidth(columns(), 0);
double itemCount = l.size();
QValueVector<int> cachedWidth;
// Here we're not using a real average, but averaging the squares of the
// column widths and then using the square root of that value. This gives
// a nice weighting to the longer columns without doing something arbitrary
// like adding a fixed amount of padding.
for(PlaylistItemList::ConstIterator it = l.begin(); it != l.end(); ++it) {
cachedWidth = (*it)->cachedWidths();
for(columnIt = m_weightDirty.begin(); columnIt != m_weightDirty.end(); ++columnIt)
averageWidth[*columnIt] += pow(double(cachedWidth[*columnIt]) , 2.0) / itemCount;
}
m_columnWeights.resize(columns(), -1);
for(columnIt = m_weightDirty.begin(); columnIt != m_weightDirty.end(); ++columnIt) {
m_columnWeights[*columnIt] = int(sqrt(averageWidth[*columnIt]) + 0.5);
// kdDebug(65432) << k_funcinfo << "m_columnWeights[" << *columnIt << "] == "
// << m_columnWeights[*columnIt] << endl;
}
m_weightDirty.clear();
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
void Playlist::slotUpdateColumnWidths()
{
if(m_disableColumnWidthUpdates)
return;
......@@ -989,9 +1048,18 @@ void Playlist::updateColumnWidths()
QValueVector<int> minimumWidth(columns(), 0);
int minimumWidthTotal = 0;
// Also build a list of either the minimum *or* the fixed width -- whichever is
// greater.
QValueVector<int> minimumFixedWidth(columns(), 0);
int minimumFixedWidthTotal = 0;
for(it = visibleColumns.begin(); it != visibleColumns.end(); ++it) {
minimumWidth[*it] = header()->fontMetrics().width(header()->label(*it) + 10);
minimumWidthTotal += minimumWidth[*it];
minimumFixedWidth[*it] = QMAX(minimumWidth[*it], m_columnFixedWidths[*it]);
minimumFixedWidthTotal += minimumFixedWidth[*it];
}
// Make sure that the width won't get any smaller than this. We have to
......@@ -1000,6 +1068,14 @@ void Playlist::updateColumnWidths()
setMinimumWidth(minimumWidthTotal + verticalScrollBar()->width());
// If we've got enough room for the fixed widths (larger than the minimum
// widths) then instead use those for our "minimum widths".
if(minimumFixedWidthTotal < visibleWidth()) {
minimumWidth = minimumFixedWidth;
minimumWidthTotal = minimumFixedWidthTotal;
}
// We've got a list of columns "weights" based on some statistics gathered
// about the widths of the items in that column. We need to find the total
// useful weight to use as a divisor for each column's weight.
......@@ -1086,48 +1162,10 @@ void Playlist::updateColumnWidths()
int remainingWidth = visibleWidth() - usedWidth;
setColumnWidth(visibleColumns.back(), columnWidth(visibleColumns.back()) + remainingWidth);
}
void Playlist::calculateColumnWeights()
{
if(m_disableColumnWidthUpdates)
return;
PlaylistItemList l = items();
QValueListConstIterator<int> columnIt;
QValueVector<double> averageWidth(columns(), 0);
double itemCount = l.size();
QValueVector<int> cachedWidth;
// Here we're not using a real average, but averaging the squares of the
// column widths and then using the square root of that value. This gives
// a nice weighting to the longer columns without doing something arbitrary
// like adding a fixed amount of padding.
for(PlaylistItemList::ConstIterator it = l.begin(); it != l.end(); ++it) {
cachedWidth = (*it)->cachedWidths();
for(columnIt = m_widthDirty.begin(); columnIt != m_widthDirty.end(); ++columnIt)
averageWidth[*columnIt] += pow(double(cachedWidth[*columnIt]) , 2.0) / itemCount;
}
m_columnWeights.resize(columns(), -1);
for(columnIt = m_widthDirty.begin(); columnIt != m_widthDirty.end(); ++columnIt) {
m_columnWeights[*columnIt] = int(sqrt(averageWidth[*columnIt]) + 0.5);
// kdDebug(65432) << k_funcinfo << "m_columnWeights[" << *columnIt << "] == "
// << m_columnWeights[*columnIt] << endl;
}
m_widthDirty.clear();
m_widthsDirty = false;
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
void Playlist::slotShowRMBMenu(QListViewItem *item, const QPoint &point, int column)
{
if(!item)
......@@ -1318,6 +1356,12 @@ void Playlist::slotToggleColumnVisible(int column)
SharedSettings::instance()->toggleColumnVisible(column - columnOffset());
}
void Playlist::slotColumnSizeChanged(int column, int, int newSize)
{
m_widthsDirty = true;
m_columnFixedWidths[column] = newSize;
}
////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////
......
......@@ -334,7 +334,7 @@ public slots:
* column widths must be recalculated. If this is called without a column
* all visible columns are marked as dirty.
*/
void slotWidthDirty(int column = -1);
void slotWeightDirty(int column = -1);
protected:
/**
......@@ -475,14 +475,11 @@ private:
*/
int leftMostVisibleColumn() const;
void updateColumnWidths();
/**
* Build the column "weights" for the weighted width mode.
*/
void calculateColumnWeights();
private:
/**
* 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.
......@@ -491,6 +488,8 @@ private:
private slots:
void slotUpdateColumnWidths();
/**
* This is just used to emit the selection as a list of PlaylistItems when
* the selection changes.
......@@ -535,6 +534,12 @@ private slots:
*/
void slotCreateGroup() { emit signalCreatePlaylist(selectedItems()); }
/**
* This slot is called when the user drags the slider in the listview header
* to manually set the size of the column.
*/
void slotColumnSizeChanged(int column, int oldSize, int newSize);
private:
StringHash m_members;
......@@ -549,12 +554,14 @@ private:
bool m_allowDuplicates;
bool m_polished;
QValueList<int> m_widthDirty;
QValueList<int> m_weightDirty;
bool m_disableColumnWidthUpdates;
/**
* The average minimum widths of columns to be used in balancing calculations.
*/
QValueVector<int> m_columnWeights;
QValueVector<int> m_columnFixedWidths;
bool m_widthsDirty;
PlaylistItemList m_randomList;
PlaylistItemList m_history;
......@@ -658,7 +665,7 @@ void Playlist::createItems(const QValueList<SiblingType *> &siblings)
emit signalCountChanged(this);
m_disableColumnWidthUpdates = false;
slotWidthDirty();
slotWeightDirty();
}
#endif
......@@ -361,7 +361,7 @@ void PlaylistItem::setup(CollectionListItem *item, Playlist *parent)
// creation -- i.e. editing the item. We'll handle item creation separately
// as that avoids this signal firing a few thousand times.
connect(this, SIGNAL(signalColumnWidthChanged(int)), parent, SLOT(slotWidthDirty(int)));
connect(this, SIGNAL(signalColumnWidthChanged(int)), parent, SLOT(slotWeightDirty(int)));
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -362,7 +362,7 @@ void PlaylistSplitter::slotAddToPlaylist(const QString &file, Playlist *list, Pl
KApplication::setOverrideCursor(Qt::waitCursor);
addImpl(file, list, after);
list->slotWidthDirty();
list->slotWeightDirty();
list->emitCountChanged();
KApplication::restoreOverrideCursor();
......@@ -388,7 +388,7 @@ void PlaylistSplitter::slotAddToPlaylist(const QStringList &files, Playlist *lis
for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
after = addImpl(*it, list, after);
list->slotWidthDirty();
list->slotWeightDirty();
list->emitCountChanged();
KApplication::restoreOverrideCursor();
......
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