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

(-)src/YQPkgList.cc (-23 / +104 lines)
Lines 93-123 Link Here
93
    setIconSize( QSize( 22, 16 ) );
93
    setIconSize( QSize( 22, 16 ) );
94
94
95
    header()->setResizeMode( QHeaderView::Interactive );
95
    header()->setResizeMode( QHeaderView::Interactive );
96
    header()->setResizeMode( statusCol(), QHeaderView::ResizeToContents	);
97
96
97
    // Set initial optimal column widths:
98
    QFontMetrics fms( header()->font() );
98
    QFontMetrics fms( header()->font() );
99
99
    _statusIconColS2Cwidth = 28;
100
    setColumnWidth( sizeCol(),		fms.width( " 9999.9 K  "	) );
100
    _nameColS2Cwidth = fms.width( "desktop-data-openSUSE-extraroom" );
101
    setColumnWidth( versionCol(),	fms.width( versionHeaderText + "   " ) );
101
    _summaryColS2Cwidth = fms.width( "A really really long text, but not too long" );
102
    setColumnWidth( nameCol(),		fms.width( "desktop-data-openSUSE-extraroom" ) );
103
    setColumnWidth( summaryCol(),	fms.width( "A really really long text, but not too long" ) );
104
105
    if ( instVersionCol() != versionCol() )
102
    if ( instVersionCol() != versionCol() )
106
    {
103
    {
107
	setColumnWidth( versionCol(),     max( fms.width( versionHeaderText + "  " ),
104
        _versionColS2Cwidth = max( fms.width( versionHeaderText + "  " ),
108
					       fms.width( " 20071220pre"           ) ) );
105
                                   fms.width( " 20071220pre"           ) );
109
	setColumnWidth( instVersionCol(), max( fms.width( instVersionHeaderText + "  " ),
106
        _instVersionColS2Cwidth = max( fms.width( instVersionHeaderText + "   " ),
110
					       fms.width( " 20071220pre"	       ) ) );
107
                                       fms.width( " 20071220pre"           ) );
111
    }
108
    }
109
    else
110
    {
111
        _versionColS2Cwidth = fms.width( versionHeaderText + "   " );
112
        _instVersionColS2Cwidth = 0;
113
    }
114
    _sizeColS2Cwidth = fms.width( " 9999.9 K  "	);
115
    /* NOTE: resizeEvent() is automatically triggered afterwards => sets column widths */
112
116
113
#if 0
114
    header()->setResizeMode( nameCol(),		QHeaderView::Stretch	);
115
    header()->setResizeMode( summaryCol(),	QHeaderView::Stretch	);
116
    header()->setResizeMode( versionCol(),	QHeaderView::Stretch	);
117
#endif
118
119
    header()->setResizeMode( sizeCol(),		QHeaderView::Fixed );
120
121
    saveColumnWidths();
117
    saveColumnWidths();
122
    createActions();
118
    createActions();
123
    createSourceRpmContextMenu();
119
    createSourceRpmContextMenu();
Lines 125-131 Link Here
125
    connect ( header(), SIGNAL( sectionClicked (int) ),
121
    connect ( header(), SIGNAL( sectionClicked (int) ),
126
	      this,	SLOT( sortByColumn (int) ) );
122
	      this,	SLOT( sortByColumn (int) ) );
127
123
128
129
}
124
}
130
125
131
126
Lines 155-161 Link Here
155
		       bool 	dimmed )
150
		       bool 	dimmed )
156
{
151
{
157
    scheduleDelayedItemsLayout();
152
    scheduleDelayedItemsLayout();
158
    
153
159
    if ( ! selectable )
154
    if ( ! selectable )
160
    {
155
    {
161
	yuiError() << "NULL zypp::ui::Selectable!" << endl;
156
	yuiError() << "NULL zypp::ui::Selectable!" << endl;
Lines 165-172 Link Here
165
    YQPkgListItem * item = new YQPkgListItem( this, selectable, zyppPkg );
160
    YQPkgListItem * item = new YQPkgListItem( this, selectable, zyppPkg );
166
    Q_CHECK_PTR( item );
161
    Q_CHECK_PTR( item );
167
162
163
    if (this->topLevelItemCount() < 50)	// DO NOT OPTIMZE, IF LIST IS ALREADY TO LARGE
164
    {
165
        setS2CcolumnWidths();	// SLOW FOR LARGE LISTS
166
        optimizeColumnWidths();
167
    }
168
168
    item->setDimmed( dimmed );
169
    item->setDimmed( dimmed );
169
    applyExcludeRules( item );
170
    applyExcludeRules( item );
171
172
    /* NOTE: There is currently no way to get the optimal column widths without setting them.
173
     *       => column widths will be set TWO times.
174
     *       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 ;-).
175
     */
176
170
}
177
}
171
178
172
179
Lines 297-304 Link Here
297
}
304
}
298
305
299
306
307
void
308
YQPkgList::setS2CcolumnWidths()
309
{
310
    // SET OPTIMAL COLUMN WIDTHS (SIZED-TO-CONTENT):
311
    this->resizeColumnToContents( statusCol() );
312
    _statusIconColS2Cwidth = this->columnWidth( statusCol() );
313
    this->resizeColumnToContents( nameCol() );
314
    _nameColS2Cwidth = this->columnWidth( nameCol() );
315
    this->resizeColumnToContents( summaryCol() );
316
    _summaryColS2Cwidth = this->columnWidth( summaryCol() );
317
    this->resizeColumnToContents( versionCol() );
318
    _versionColS2Cwidth = this->columnWidth( versionCol() );
319
    if ( instVersionCol() != versionCol() )
320
    {
321
        this->resizeColumnToContents( instVersionCol() );
322
       _instVersionColS2Cwidth = this->columnWidth( instVersionCol() );
323
    }
324
    this->resizeColumnToContents( sizeCol() );
325
    _sizeColS2Cwidth = this->columnWidth( sizeCol() );
300
326
327
    /* NOTE: There is currently no way to get the optimal column widths without setting them. */
328
329
}
330
331
301
void
332
void
333
YQPkgList::optimizeColumnWidths()
334
{
335
    int visibleSpace = 0;
336
    int s2cWidthsSum = 0;
337
    int numOptCol = 4;
338
339
    s2cWidthsSum = _statusIconColS2Cwidth + _nameColS2Cwidth + _summaryColS2Cwidth + _versionColS2Cwidth + _sizeColS2Cwidth;
340
    if ( instVersionCol() != versionCol() )
341
    {
342
        s2cWidthsSum += _instVersionColS2Cwidth;
343
        numOptCol++;
344
    }
345
    // CHECK IF WE HAVE LESS VISIBLE SPACE THAN WE NEED:
346
    visibleSpace = this->viewport()->width();
347
    if (visibleSpace < 0) return;
348
    if (s2cWidthsSum >= visibleSpace)	// THERE IS NOT ENOUGH VISIBLE SPACE TO SHOW ALL CLOUMNS WITH OPTIMAL WIDTHS
349
    {
350
        // ONLY REDUCE WIDTH OF THE "summary"-COLUMN; IF THIS IS NOT ENOUGH, WE WILL GET A HORIZONTAL SCROLL BAR
351
        int newSummaryWidth = visibleSpace - s2cWidthsSum + _summaryColS2Cwidth;
352
        if (newSummaryWidth < 100)
353
            newSummaryWidth = 100;
354
        this->setColumnWidth( summaryCol(), newSummaryWidth);
355
    }
356
    else	// THERE IS ENOUGH VISIBLE SPACE
357
    {
358
        // DISTRIBUTE REMAINING VISIBLE SPACE TO ALL COLUMNS (except the satusIcon-column):
359
        // Calculate additional column widths:
360
        int addSpace = (visibleSpace - s2cWidthsSum) / numOptCol;
361
        int addSpaceR = (visibleSpace - s2cWidthsSum) % numOptCol;
362
        // Set new column widths:
363
        this->setColumnWidth( statusCol(), _statusIconColS2Cwidth );
364
        this->setColumnWidth( nameCol(), _nameColS2Cwidth + addSpace );
365
        this->setColumnWidth( summaryCol(), _summaryColS2Cwidth + addSpace );
366
        this->setColumnWidth( versionCol(), _versionColS2Cwidth + addSpace );
367
        if ( instVersionCol() != versionCol() )
368
            this->setColumnWidth( instVersionCol(), _instVersionColS2Cwidth + addSpace );
369
        this->setColumnWidth( sizeCol(), _sizeColS2Cwidth + addSpace + addSpaceR );
370
    }
371
}
372
373
374
void
375
YQPkgList::resizeEvent(QResizeEvent *event)
376
{
377
    optimizeColumnWidths();
378
    event->accept();
379
}
380
381
382
383
void
302
YQPkgList::createNotInstalledContextMenu()
384
YQPkgList::createNotInstalledContextMenu()
303
{
385
{
304
    _notInstalledContextMenu = new QMenu( this );
386
    _notInstalledContextMenu = new QMenu( this );
Lines 604-612 Link Here
604
	_zyppPkg = tryCastToZyppPkg( selectable->theObj() );
686
	_zyppPkg = tryCastToZyppPkg( selectable->theObj() );
605
687
606
    setSourceRpmIcon();
688
    setSourceRpmIcon();
607
    
689
608
    setTextAlignment( sizeCol(), Qt::AlignRight );
690
    setTextAlignment( sizeCol(), Qt::AlignRight );
609
    setSizeHint( sizeCol(), QSize( QFontMetrics( pkgList->font() ).width( text( sizeCol() ) ), 10 ) );
610
}
691
}
611
692
612
693
(-)src/YQPkgList.h (-2 / +27 lines)
Lines 22-27 Link Here
22
22
23
#include <YQPkgObjList.h>
23
#include <YQPkgObjList.h>
24
#include <QMenu>
24
#include <QMenu>
25
#include <QResizeEvent>
25
26
26
class YQPkgListItem;
27
class YQPkgListItem;
27
28
Lines 193-203 Link Here
193
     **/
194
     **/
194
    void setInstallListSourceRpms( bool inst );
195
    void setInstallListSourceRpms( bool inst );
195
196
197
    /**
198
     * Set and save optimal column widths depending on content only
199
     * There is currently no way to get the optimal widths without setting them, so we have to do it.
200
     **/
201
    void setS2CcolumnWidths();
196
202
197
    // Data members
203
    /**
204
     * Optimizes the column widths depending on content and the available horizontal space.
205
     **/
206
    void optimizeColumnWidths();
198
207
208
    /**
209
     * Handler for resize events.
210
     * Triggers column width optimization.
211
     **/
212
    void resizeEvent(QResizeEvent *event);
213
214
215
    // *** Data members:
216
199
    int			_srpmStatusCol;
217
    int			_srpmStatusCol;
200
    QMenu *	_sourceRpmContextMenu;
218
    QMenu *		_sourceRpmContextMenu;
219
    // Last optimal (sized-to-content) column widths
220
    int _statusIconColS2Cwidth;
221
    int _nameColS2Cwidth;
222
    int _summaryColS2Cwidth;
223
    int _versionColS2Cwidth;
224
    int _instVersionColS2Cwidth;
225
    int _sizeColS2Cwidth;
201
226
202
227
203
public:
228
public:

Return to bug 441828