17 #include <q3stylesheet.h>
22 #include <QMouseEvent>
42 mSortByThreadChangeDate( false ),
45 mShowingFolder( false ),
48 mPaintInfo.
subCol = addColumn( i18n(
"Subject"), 310 );
49 mPaintInfo.
senderCol = addColumn( i18n(
"From"), 115 );
50 mPaintInfo.
scoreCol = addColumn( i18n(
"Score"), 42 );
51 mPaintInfo.
sizeCol = addColumn( i18n(
"Lines"), 42 );
52 mPaintInfo.
dateCol = addColumn( i18n(
"Date"), 102 );
54 setDropVisualizer(
false );
55 setDropHighlighter(
false );
56 setItemsRenameable(
false );
57 setItemsMovable(
false );
58 setAcceptDrops(
false );
59 setDragEnabled(
true );
60 setAllColumnsShowFocus(
true );
61 setSelectionMode( Q3ListView::Extended );
62 setShowSortIndicator(
true );
63 setShadeSortColumn (
true );
64 setRootIsDecorated(
true );
66 header()->setMovingEnabled(
true );
67 setColumnAlignment( mPaintInfo.
sizeCol, Qt::AlignRight );
68 setColumnAlignment( mPaintInfo.
scoreCol, Qt::AlignRight );
71 disconnect( header(), SIGNAL(sizeChange(
int,
int,
int)) );
72 connect( header(), SIGNAL(sizeChange(
int,
int,
int)),
73 SLOT(slotSizeChanged(
int,
int,
int)) );
76 mPopup =
new KMenu(
this );
77 mPopup->addTitle( i18n(
"View Columns") );
78 mPopup->setCheckable(
true );
82 connect( mPopup, SIGNAL(activated(
int)),
this, SLOT(
toggleColumn(
int)) );
93 installEventFilter(
this );
107 KConfigGroup conf(
knGlobals.config(),
"HeaderView" );
108 mSortByThreadChangeDate = conf.readEntry(
"sortByThreadChangeDate",
false );
109 restoreLayout(
knGlobals.config(),
"HeaderView" );
114 if ( !mShowingFolder )
117 mDateFormatter.setCustomFormat(
knGlobals.settings()->customDateFormat() );
118 mDateFormatter.setFormat(
knGlobals.settings()->dateFormat() );
124 setAlternateBackground(
knGlobals.settings()->alternateBackgroundColor() );
125 setFont(
knGlobals.settings()->articleListFont() );
131 KConfigGroup conf(
knGlobals.config(),
"HeaderView" );
132 conf.writeEntry(
"sortByThreadChangeDate", mSortByThreadChangeDate );
133 saveLayout(
knGlobals.config(),
"HeaderView" );
136 if ( !mShowingFolder )
150 repaintItem( mActiveItem );
155 setSelected( item,
true );
179 parent = parent->
parent();
183 int y = itemPos( i );
186 if (
knGlobals.settings()->smartScrolling() &&
187 ((y + h + 5) >= (contentsY() + visibleHeight()) ||
188 (y - 5 < contentsY())) )
190 ensureVisible( contentsX(), y + h/2, 0, h/2 );
191 mDelayedCenter = y + h/2;
194 ensureVisible( contentsX(), y + h/2, 0, h/2 );
199 void KNHeaderView::slotCenterDelayed()
201 if ( mDelayedCenter != -1 )
202 ensureVisible( contentsX(), mDelayedCenter, 0, visibleHeight() / 2 );
208 if ( column == mSortCol ) {
209 mSortAsc = ascending;
210 if ( mInitDone && column == mPaintInfo.
dateCol && ascending )
211 mSortByThreadChangeDate = !mSortByThreadChangeDate;
217 K3ListView::setSorting( column, ascending );
220 ensureItemVisible( currentItem() );
222 if ( mSortByThreadChangeDate )
223 setColumnText( mPaintInfo.
dateCol , i18n(
"Date (thread changed)") );
225 setColumnText( mPaintInfo.
dateCol, i18n(
"Date") );
235 if (it->isExpandable())
245 setSelectionAnchor( currentItem() );
258 setSelectionAnchor( currentItem() );
270 ensureItemVisible( currentItem() );
282 ensureItemVisible( currentItem() );
297 if ( !
knGlobals.groupManager()->currentGroup() )
312 if ( !current->
isActive() && !art->isRead() )
315 if ( current->isExpandable() && art->hasUnreadFollowUps() && !current->isOpen() )
316 setOpen( current,
true );
322 if ( !art->isRead() )
325 if ( next->isExpandable() && art->hasUnreadFollowUps() && !next->isOpen() )
326 setOpen( next,
true );
334 setSelectionAnchor( currentItem() );
346 if ( !
knGlobals.groupManager()->currentGroup() )
358 if ( current->depth() == 0 && !current->
isActive() && (!art->isRead() || art->hasUnreadFollowUps()) )
366 if ( next->depth() == 0 ) {
367 if ( !art->isRead() || art->hasUnreadFollowUps() )
380 setSelectionAnchor( currentItem() );
394 switch ( static_cast<KPaintInfo::ColumnIds>( column ) )
415 mPopup->setItemChecked( column, *show );
418 header()->setResizeEnabled(
true, *col );
419 setColumnWidth( *col, width );
422 header()->setResizeEnabled(
false, *col );
423 header()->setStretchEnabled(
false, *col );
434 mShowingFolder =
false;
435 header()->setLabel( mPaintInfo.
senderCol, i18n(
"From") );
442 mShowingFolder =
true;
443 header()->setLabel( mPaintInfo.
senderCol, i18n(
"Newsgroups / To") );
452 if (e->
type() == QEvent::ApplicationPaletteChange)
455 return K3ListView::event(e);
462 bool selectMode=(( e->
modifiers() & Qt::ShiftModifier ) || ( e->
modifiers() & Qt::ControlModifier ));
464 QPoint vp = contentsToViewport(e->
pos());
467 K3ListView::contentsMousePressEvent( e );
470 int decoLeft = header()->sectionPos( 0 ) +
471 treeStepSize() * ( (i->depth() - 1) + ( rootIsDecorated() ? 1 : 0) );
472 int decoRight = qMin( decoLeft + treeStepSize() + itemMargin(),
473 header()->sectionPos( 0 ) + header()->sectionSize( 0 ) );
474 bool rootDecoClicked = vp.
x() > decoLeft && vp.
x() < decoRight;
476 if( !selectMode && i->isSelected() && !rootDecoClicked )
492 K3ListView::contentsMouseDoubleClickEvent( e );
504 case Qt::Key_Backspace:
514 K3ListView::keyPressEvent (e);
520 #warning Port this to QDrag once the view doesnot derive from K3ListView any more
532 void KNHeaderView::slotSizeChanged(
int section,
int,
int newSize )
534 viewport()->repaint( header()->sectionPos(section), 0, newSize, visibleHeight() );
541 if ( e->
type() == QEvent::MouseButtonPress &&
542 static_cast<QMouseEvent*
>(e)->button() == Qt::RightButton &&
545 mPopup->popup( static_cast<QMouseEvent*>(e)->globalPos() );
549 return K3ListView::eventFilter(o, e);
559 KNHeaderViewToolTip::KNHeaderViewToolTip(
KNHeaderView *parent ) :
566 void KNHeaderViewToolTip::maybeTip(
const QPoint &p )
571 const int column = listView->header()->sectionAt( p.
x() );
578 const QRect itemRect = listView->itemRect( item );
581 const QRect headerRect = listView->header()->sectionRect( column );
Q3ListViewItem * parent() const
void setColor(ColorGroup group, ColorRole role, const QColor &color)
virtual QString text(int col) const
bool isExpandable() const
Q3ListViewItem * itemAbove() const
virtual void setOpen(bool o)
static int setCurrentItem(K3ListBox *box, const QString &s)
bool showToolTip(int column) const
boost::shared_ptr< KNRemoteArticle > Ptr
Shared pointer to a KNRemoteArticle. To be used instead of raw KNRemoteArticle*.
QString escape(const QString &plain)
KNRemoteArticle represents an article, whos body has to be retrieved from a remote host or from the l...
const QPoint & pos() const
Q3DragObject * dragObject()
#define knGlobals
Keep compatibility with the old way.
Q3ListViewItem * itemBelow() const
virtual bool event(QEvent *e)