KDevelop API Documentation

partwidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by KDevelop authors                                *
00003  *   kdevelop-devel@kde.org                                                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include <qwhatsthis.h>
00013 #include <qvbox.h>
00014 #include <qlayout.h>
00015 #include <qtoolbutton.h>
00016 #include <qdom.h>
00017 #include <kcombobox.h>
00018 #include <kaction.h>
00019 #include <kdebug.h>
00020 #include <kiconloader.h>
00021 #include <klocale.h>
00022 
00023 #include "kdevvcsfileinfoprovider.h"
00024 #include "kdevversioncontrol.h"
00025 #include "kdevcore.h"
00026 #include "kdevproject.h"
00027 #include "kdevmainwindow.h"
00028 
00029 #include "fileviewpart.h"
00030 #include "filetreewidget.h"
00031 #include "partwidget.h"
00032 
00034 // class PartWidget
00036 
00037 PartWidget::PartWidget( FileViewPart *part, QWidget *parent )
00038     : QVBox( parent, "fileviewpartwidget" ), m_filetree( 0 ),
00039     m_filter( 0 ), m_btnFilter( 0 ), m_part( part )
00040 {
00041     Q_ASSERT( part && parent );
00042 
00043     KDevVCSFileInfoProvider *infoProvider = 0;
00044     if (part && part->versionControl() && part->versionControl()->fileInfoProvider())
00045         infoProvider = part->versionControl()->fileInfoProvider();
00046 
00047     m_filetree = new FileTreeWidget( m_part, this, infoProvider );
00048     setCaption(i18n("File Tree"));
00049     m_filetree->setCaption(i18n("File Tree"));
00050     m_filetree->setIcon(SmallIcon("folder"));
00051     QWhatsThis::add(m_filetree, i18n("<b>File tree</b><p>"
00052                                     "The file viewer shows all files of the project "
00053                                     "in a tree layout."));
00054 
00055     QHBox* filterBox = new QHBox( this );
00056     m_btnFilter = new QToolButton( filterBox );
00057     m_btnFilter->setIconSet( SmallIconSet("filter" ) );
00058     m_btnFilter->setToggleButton( true );
00059     m_filter = new KHistoryCombo( true, filterBox, "filter");
00060     m_filter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
00061     filterBox->setStretchFactor(m_filter, 2);
00062 
00063     connect( m_btnFilter, SIGNAL( clicked() ), this, SLOT( slotBtnFilterClick() ) );
00064     connect( m_filter, SIGNAL( activated(const QString&) ), this, SLOT( slotFilterChange(const QString&) ) );
00065     connect( m_filter, SIGNAL( returnPressed(const QString&) ),
00066              m_filter, SLOT( addToHistory(const QString&) ) );
00067 
00068     QWhatsThis::add
00069         ( m_filter,
00070                 i18n("<p>Here you can enter a name filter to limit which files are <b>not displayed</b>."
00071                      "<p>To clear the filter, toggle off the filter button to the left."
00072                      "<p>To reapply the last filter used, toggle on the filter button." ) );
00073     QWhatsThis::add
00074         ( m_btnFilter,
00075                 i18n("<p>This button clears the name filter when toggled off, or "
00076                      "reapplies the last filter used when toggled on.") );
00077 
00078     m_filter->insertItem( m_filetree->hidePatterns() );
00079 }
00080 
00082 
00083 PartWidget::~PartWidget()
00084 {
00085 }
00086 
00088 
00089 void PartWidget::showProjectFiles()
00090 {
00091     m_filetree->openDirectory( m_part->project()->projectDirectory() );
00092     m_filetree->applyHidePatterns( m_filetree->hidePatterns() );
00093 }
00094 
00096 
00097 void PartWidget::slotFilterChange( const QString & nf )
00098 {
00099     QString f = nf.stripWhiteSpace();
00100     bool empty = f.isEmpty() || f == "*";
00101     if ( empty )
00102     {
00103         m_filter->lineEdit()->setText( QString::null );
00104         QToolTip::add( m_btnFilter, QString( i18n("Apply last filter (\"%1\")") ).arg( m_lastFilter ) );
00105     }
00106     else
00107     {
00108         m_lastFilter = f;
00109         QToolTip::add( m_btnFilter, i18n("Clear filter") );
00110     }
00111     m_btnFilter->setOn( !empty );
00112     // this will be never true after the m_filter has been used;)
00113     m_btnFilter->setEnabled( !( empty && m_lastFilter.isEmpty() ) );
00114 
00115     m_filetree->applyHidePatterns( f );
00116 }
00117 
00119 /*
00120    When the button in the filter box toggles:
00121    If off:
00122    If the name filer is anything but "" or "*", reset it.
00123    If on:
00124    Set last filter.
00125 */
00126 void PartWidget::slotBtnFilterClick()
00127 {
00128     if ( !m_btnFilter->isOn() )
00129     {
00130         slotFilterChange( QString::null );
00131     }
00132     else
00133     {
00134         m_filter->lineEdit()->setText( m_lastFilter );
00135         slotFilterChange( m_lastFilter );
00136     }
00137 }
00138 
00139 void PartWidget::focusInEvent( QFocusEvent * )
00140 {
00141     m_filetree->setFocus();
00142 }
00143 
00144 #include "partwidget.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003