Bugzilla – Attachment 271070 Details for
Bug 441828
[Qt4-Pkg] Column widths in package list
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
IDP Log In
|
Forgot Password
[patch]
Another patch for discussion
columnSizeOptimization.patch (text/plain), 4.31 KB, created by
Frank Schäfer
on 2009-02-08 17:54:01 UTC
(
hide
)
Description:
Another patch for discussion
Filename:
MIME Type:
Creator:
Frank Schäfer
Created:
2009-02-08 17:54:01 UTC
Size:
4.31 KB
patch
obsolete
>Index: src/YQPkgList.cc >=================================================================== >--- src/YQPkgList.cc (Revision 55316) >+++ src/YQPkgList.cc (Arbeitskopie) >@@ -116,8 +116,6 @@ > header()->setResizeMode( versionCol(), QHeaderView::Stretch ); > #endif > >- header()->setResizeMode( sizeCol(), QHeaderView::Fixed ); >- > saveColumnWidths(); > createActions(); > createSourceRpmContextMenu(); >@@ -155,7 +153,7 @@ > bool dimmed ) > { > scheduleDelayedItemsLayout(); >- >+ > if ( ! selectable ) > { > yuiError() << "NULL zypp::ui::Selectable!" << endl; >@@ -165,6 +163,8 @@ > YQPkgListItem * item = new YQPkgListItem( this, selectable, zyppPkg ); > Q_CHECK_PTR( item ); > >+ optimizeColumnWidths(); >+ > item->setDimmed( dimmed ); > applyExcludeRules( item ); > } >@@ -297,7 +297,74 @@ > } > > >+void >+YQPkgList::optimizeColumnWidths() >+{ >+ int numCol = 0; >+ int visibleSpace = 0; >+ //int cWidths_old[6] = {0,}; >+ int s2cWidths[6] = {0,}; >+ int s2cWidthsSum = 0; >+ int k = 0; > >+ if (this->topLevelItemCount() > 50) return; // DO NOT OPTIMZE, IF LIST IS ALREADY TO LARGE (IT'S TOO SLOW) >+ numCol = this->columnCount(); >+ if (numCol < 1) return; >+ // SET OPTIMAL COLUMN WIDTHS (SIZED-TO-CONTENT): >+ for (k=0; k<numCol; k++) >+ { >+ //cWidths_old[k] = this->columnWidth(k); // backup current column width >+ this->resizeColumnToContents(k); >+ s2cWidths[k] = this->columnWidth(k); >+ s2cWidthsSum += s2cWidths[k]; >+ } >+ // CHECK IF WE HAVE LESS VISIBLE SPACE THAN WE NEED: >+ visibleSpace = this->viewport()->width(); >+ if (s2cWidthsSum >= visibleSpace) >+ { >+ // WHAT DO WE DO IF THERE IS NOT ENOUGH SPACE TO SHOW ALL COLUMNS WITH OPTIMAL WIDTHS ? >+ >+ // SOLUTION 1: Restore initial widths (do nothing) >+ //for (k=0; k<numCol; k++) >+ // this->setColumnWidth( k, cWidths_old[k]); >+ >+ // SOLUTION 2: Only reduce width of the "summary"-column; if this is not enough, we will get a horizontal scroll bar >+ int newSummaryWidth = visibleSpace - s2cWidthsSum + s2cWidths[ summaryCol() ]; >+ if (newSummaryWidth < 100) >+ newSummaryWidth = 100; >+ this->setColumnWidth( summaryCol(), newSummaryWidth); >+ >+ } >+ else // WE HAVE ENOUGH VISIBLE SPACE >+ { >+ // DISTRIBUTE REMAINING VISIBLE SPACE TO ALL COLUMNS (except the satusIcon-column): >+ // PRO: LOOKS MUCH BETTER >+ // CONTRA: WE WILL WASTE SPACE, IF THE WINDOW WIDTH WILL BE REDUCED >+ >+ // CALCULATE ADDITIONAL CULUMN WIDTHS: >+ int addSpace = (visibleSpace - s2cWidthsSum) / (numCol - 1); >+ int addSpaceLC = (visibleSpace - s2cWidthsSum) % (numCol - 1); // last column (without statusIcon columns) >+ // SET NEW COLUMN WIDTHS: >+ int lindex = numCol - 1; >+ if (statusCol() == lindex) >+ lindex--; >+ for (k=0; k<lindex; k++) >+ { >+ if (k != statusCol()) >+ this->setColumnWidth( k, s2cWidths[k] + addSpace ); >+ } >+ this->setColumnWidth( lindex, s2cWidths[lindex] + addSpace + addSpaceLC ); >+ } >+ >+ /* NOTE: There is currently no way to get the optimal column widths without setting them. >+ * => depending on the available visible space and the selected strategy, column widths may be set TWO times in this function. >+ * Although this is no "nice" solution, we don't have to worry about visual effects. It's really fast and therefore not visible for the user ;-). >+ */ >+ >+} >+ >+ >+ > void > YQPkgList::createNotInstalledContextMenu() > { >@@ -604,9 +671,8 @@ > _zyppPkg = tryCastToZyppPkg( selectable->theObj() ); > > setSourceRpmIcon(); >- >+ > setTextAlignment( sizeCol(), Qt::AlignRight ); >- setSizeHint( sizeCol(), QSize( QFontMetrics( pkgList->font() ).width( text( sizeCol() ) ), 10 ) ); > } > > >Index: src/YQPkgList.h >=================================================================== >--- src/YQPkgList.h (Revision 55316) >+++ src/YQPkgList.h (Arbeitskopie) >@@ -193,11 +193,16 @@ > **/ > void setInstallListSourceRpms( bool inst ); > >+ /** >+ * Optimizes the column widths depending on content and the available space. >+ **/ >+ void optimizeColumnWidths(); > >+ > // Data members > > int _srpmStatusCol; >- QMenu * _sourceRpmContextMenu; >+ QMenu * _sourceRpmContextMenu; > > > public:
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
Attachments on
bug 441828
:
251881
|
256913
|
259514
| 271070 |
271962