View | Details | Raw Unified | Return to bug 441828
Collapse All | Expand All

(-)src/YQPkgList.cc (-5 / +71 lines)
Lines 116-123 Link Here
116
    header()->setResizeMode( versionCol(),	QHeaderView::Stretch	);
116
    header()->setResizeMode( versionCol(),	QHeaderView::Stretch	);
117
#endif
117
#endif
118
118
119
    header()->setResizeMode( sizeCol(),		QHeaderView::Fixed );
120
121
    saveColumnWidths();
119
    saveColumnWidths();
122
    createActions();
120
    createActions();
123
    createSourceRpmContextMenu();
121
    createSourceRpmContextMenu();
Lines 155-161 Link Here
155
		       bool 	dimmed )
153
		       bool 	dimmed )
156
{
154
{
157
    scheduleDelayedItemsLayout();
155
    scheduleDelayedItemsLayout();
158
    
156
159
    if ( ! selectable )
157
    if ( ! selectable )
160
    {
158
    {
161
	yuiError() << "NULL zypp::ui::Selectable!" << endl;
159
	yuiError() << "NULL zypp::ui::Selectable!" << endl;
Lines 165-170 Link Here
165
    YQPkgListItem * item = new YQPkgListItem( this, selectable, zyppPkg );
163
    YQPkgListItem * item = new YQPkgListItem( this, selectable, zyppPkg );
166
    Q_CHECK_PTR( item );
164
    Q_CHECK_PTR( item );
167
165
166
    optimizeColumnWidths();
167
168
    item->setDimmed( dimmed );
168
    item->setDimmed( dimmed );
169
    applyExcludeRules( item );
169
    applyExcludeRules( item );
170
}
170
}
Lines 297-303 Link Here
297
}
297
}
298
298
299
299
300
void
301
YQPkgList::optimizeColumnWidths()
302
{
303
    int numCol = 0;
304
    int visibleSpace = 0;
305
    //int cWidths_old[6] = {0,};
306
    int s2cWidths[6] = {0,};
307
    int s2cWidthsSum = 0;
308
    int k = 0;
300
309
310
    if (this->topLevelItemCount() > 50) return; // DO NOT OPTIMZE, IF LIST IS ALREADY TO LARGE (IT'S TOO SLOW)
311
    numCol = this->columnCount();
312
    if (numCol < 1) return;
313
    // SET OPTIMAL COLUMN WIDTHS (SIZED-TO-CONTENT):
314
    for (k=0; k<numCol; k++)
315
    {
316
        //cWidths_old[k] = this->columnWidth(k);	// backup current column width
317
        this->resizeColumnToContents(k);
318
        s2cWidths[k] = this->columnWidth(k);
319
        s2cWidthsSum += s2cWidths[k];
320
    }
321
    // CHECK IF WE HAVE LESS VISIBLE SPACE THAN WE NEED:
322
    visibleSpace = this->viewport()->width();
323
    if (s2cWidthsSum >= visibleSpace)
324
    {
325
        // WHAT DO WE DO IF THERE IS NOT ENOUGH SPACE TO SHOW ALL COLUMNS WITH OPTIMAL WIDTHS ?
326
327
        // SOLUTION 1: Restore initial widths (do nothing)
328
        //for (k=0; k<numCol; k++)
329
        //    this->setColumnWidth( k, cWidths_old[k]);
330
331
        // SOLUTION 2: Only reduce width of the "summary"-column; if this is not enough, we will get a horizontal scroll bar
332
        int newSummaryWidth = visibleSpace - s2cWidthsSum + s2cWidths[ summaryCol() ];
333
        if (newSummaryWidth < 100)
334
            newSummaryWidth = 100;
335
        this->setColumnWidth( summaryCol(), newSummaryWidth);
336
337
    }
338
    else	// WE HAVE ENOUGH VISIBLE SPACE
339
    {
340
        // DISTRIBUTE REMAINING VISIBLE SPACE TO ALL COLUMNS (except the satusIcon-column):
341
        // PRO:		LOOKS MUCH BETTER
342
        // CONTRA:	WE WILL WASTE SPACE, IF THE WINDOW WIDTH WILL BE REDUCED
343
344
        // CALCULATE ADDITIONAL CULUMN WIDTHS:
345
        int addSpace = (visibleSpace - s2cWidthsSum) / (numCol - 1);
346
        int addSpaceLC = (visibleSpace - s2cWidthsSum) % (numCol - 1);	// last column (without statusIcon columns)
347
        // SET NEW COLUMN WIDTHS:
348
        int lindex = numCol - 1;
349
        if (statusCol() == lindex)
350
            lindex--;
351
        for (k=0; k<lindex; k++)
352
        {
353
            if (k != statusCol())
354
                this->setColumnWidth( k, s2cWidths[k] + addSpace );
355
        }
356
        this->setColumnWidth( lindex, s2cWidths[lindex] + addSpace + addSpaceLC );
357
    }
358
359
    /* NOTE: There is currently no way to get the optimal column widths without setting them.
360
     *       => depending on the available visible space and the selected strategy, column widths may be set TWO times in this function.
361
     *       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 ;-).
362
     */
363
364
}
365
366
367
301
void
368
void
302
YQPkgList::createNotInstalledContextMenu()
369
YQPkgList::createNotInstalledContextMenu()
303
{
370
{
Lines 604-612 Link Here
604
	_zyppPkg = tryCastToZyppPkg( selectable->theObj() );
671
	_zyppPkg = tryCastToZyppPkg( selectable->theObj() );
605
672
606
    setSourceRpmIcon();
673
    setSourceRpmIcon();
607
    
674
608
    setTextAlignment( sizeCol(), Qt::AlignRight );
675
    setTextAlignment( sizeCol(), Qt::AlignRight );
609
    setSizeHint( sizeCol(), QSize( QFontMetrics( pkgList->font() ).width( text( sizeCol() ) ), 10 ) );
610
}
676
}
611
677
612
678
(-)src/YQPkgList.h (-1 / +6 lines)
Lines 193-203 Link Here
193
     **/
193
     **/
194
    void setInstallListSourceRpms( bool inst );
194
    void setInstallListSourceRpms( bool inst );
195
195
196
    /**
197
     * Optimizes the column widths depending on content and the available space.
198
     **/
199
    void optimizeColumnWidths();
196
200
201
197
    // Data members
202
    // Data members
198
203
199
    int			_srpmStatusCol;
204
    int			_srpmStatusCol;
200
    QMenu *	_sourceRpmContextMenu;
205
    QMenu *		_sourceRpmContextMenu;
201
206
202
207
203
public:
208
public:

Return to bug 441828