[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: konq_frame header
From: Mark Deneen <deneen () bucknell ! edu>
Date: 2001-05-09 21:09:41
[Download RAW message or body]
I've added a header to all konq frames which are toggleable. It is a simple
class which just has a label and a button. The label is the title of the
header, and the button will toggle the part. (closing it)
I have a screenshot up at http://tick.dhs.org/~deneen/kpart-header.png.
It only makes itself visible if the widget in the part calls setCaption(). I
had to do a little fudging with a QTimer::singleShot to make it work.
(thanks wildfox)
Please take a look at the patch. I haven't done very much with Qt before..
so criticism is welcome. ;-)
I'm not on kfm-devel, so please reply directly to me.
(If I oafed the patch, just tell me. :-))
I tried to keep the spacing/tabs the same as the source files, but I don't
know how well I did!
Regards,
Mark Deneen
["konq.diff" (text/x-c)]
Index: konq_frame.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_frame.cc,v
retrieving revision 1.122
diff -u -3 -p -r1.122 konq_frame.cc
--- konq_frame.cc 2001/04/12 11:11:31 1.122
+++ konq_frame.cc 2001/05/09 21:00:28
@@ -25,6 +25,7 @@
#include <qsplitter.h>
#include <qwhatsthis.h>
#include <qtimer.h>
+#include <qpushbutton.h>
#include <kapp.h>
#include <kdebug.h>
@@ -34,6 +35,7 @@
#include <kprogress.h>
#include <klocale.h>
#include <kseparator.h>
+#include <kaction.h>
#include <kparts/browserextension.h>
#include <kparts/event.h>
@@ -281,6 +283,80 @@ void KonqFrameStatusBar::paintEvent(QPai
#endif
}
+
+KonqFrameHeader::KonqFrameHeader( KonqFrame *_parent, const char *_name )
+:QWidget( _parent, _name )
+,m_pParentKonqFrame( _parent )
+{
+
+ m_pAction = 0L;
+ m_pLayout = new QHBoxLayout( this, 0, -1, "KonqFrame's QVBoxLayout" );
+ m_pHeaderLabel = new QLabel( this, "KonqFrameHeader label" );
+ m_pHeaderLabel->setAlignment(AlignCenter);
+ m_pHeaderLabel->setFrameStyle( QFrame::StyledPanel );
+
+ m_pCloseButton = new QPushButton( this );
+ m_pLayout->addWidget( m_pHeaderLabel );
+ m_pLayout->addWidget( m_pCloseButton );
+
+ m_pLayout->setStretchFactor( m_pHeaderLabel, 1 );
+ m_pLayout->setStretchFactor( m_pCloseButton, 0 );
+ m_pCloseButton->setText("X");
+
+ m_pCloseButton->setFocusPolicy(NoFocus);
+}
+
+KonqFrameHeader::~KonqFrameHeader()
+{
+ if(m_pLayout) delete m_pLayout;
+}
+
+void KonqFrameHeader::slotConnectToNewView(KonqView *, KParts::ReadOnlyPart \
*,KParts::ReadOnlyPart *newOne) +{
+ if (newOne!=0)
+ {
+ connect(m_pCloseButton, SIGNAL(clicked()), this, SLOT(slotDoAction()));
+ newOne->widget()->installEventFilter(this);
+ }
+}
+
+void KonqFrameHeader::slotDoAction()
+{
+ if( m_pAction )
+ m_pAction->activate();
+}
+void KonqFrameHeader::slotSetHeaderText(const QString &text)
+{
+ m_pHeaderLabel->setText(text);
+}
+
+void KonqFrameHeader::setAction( KAction *inAction )
+{
+ m_pAction = inAction;
+}
+
+
+bool KonqFrameHeader::eventFilter(QObject* /*obj*/, QEvent *ev)
+{
+ if( ev->type()==QEvent::CaptionChange )
+ {
+ if( m_pParentKonqFrame->childView() ) // just me being extra careful..
+ {
+ // don't set title for things that are not toggle views.
+ if( m_pParentKonqFrame->childView()->isToggleView() )
+ {
+ QVariant v = \
m_pParentKonqFrame->part()->widget()->property("caption"); + if( \
v.isValid() ) + slotSetHeaderText(v.asString());
+ if( !isVisible() ) show();
+
+ return true;
+ }
+ }
+ };
+ return false;
+};
+
//###################################################################
KonqFrame::KonqFrame( KonqFrameContainer *_parentContainer, const char *_name )
@@ -291,6 +367,7 @@ KonqFrame::KonqFrame( KonqFrameContainer
// the frame statusbar
m_pStatusBar = new KonqFrameStatusBar( this, "KonquerorFrameStatusBar");
+ m_pHeader = new KonqFrameHeader(this, "KonquerorFrameHeader");
connect(m_pStatusBar, SIGNAL(clicked()), this, SLOT(slotStatusBarClicked()));
connect( m_pStatusBar, SIGNAL( linkedViewClicked( bool ) ), this, SLOT( \
slotLinkedViewClicked( bool ) ) ); m_separator = 0;
@@ -347,6 +424,7 @@ KParts::ReadOnlyPart *KonqFrame::attach(
attachInternal();
m_pStatusBar->slotConnectToNewView(0, 0,m_pPart);
+ m_pHeader->slotConnectToNewView(0, 0,m_pPart);
return m_pPart;
}
@@ -357,11 +435,15 @@ void KonqFrame::attachInternal()
m_pLayout = new QVBoxLayout( this, 0, -1, "KonqFrame's QVBoxLayout" );
+ m_pLayout->addWidget( m_pHeader );
+
m_pLayout->addWidget( m_pPart->widget() );
m_pLayout->addWidget( m_pStatusBar );
m_pPart->widget()->show();
m_pStatusBar->show();
+ m_pHeader->hide();
+
m_pLayout->activate();
m_pPart->widget()->installEventFilter(this);
@@ -396,8 +478,10 @@ void KonqFrame::setView( KonqView* child
{
connect(m_pView,SIGNAL(sigPartChanged(KonqView *, KParts::ReadOnlyPart \
*,KParts::ReadOnlyPart *)),
m_pStatusBar,SLOT(slotConnectToNewView(KonqView *, KParts::ReadOnlyPart \
*,KParts::ReadOnlyPart *)));
- //connect(m_pView->view(),SIGNAL(setStatusBarText(const QString &)),
- //m_pHeader,SLOT(slotDisplayStatusText(const QString&)));
+ connect(m_pView,SIGNAL(sigPartChanged(KonqView *, KParts::ReadOnlyPart \
*,KParts::ReadOnlyPart *)), + \
m_pHeader,SLOT(slotConnectToNewView(KonqView *, KParts::ReadOnlyPart \
*,KParts::ReadOnlyPart *))); +
+// connect(m_pView->view(),SIGNAL(setStatusBarText(const QString \
&)),m_pHeader,SLOT(slotDisplayStatusText(const QString&))); }
};
Index: konq_frame.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_frame.h,v
retrieving revision 1.62
diff -u -3 -p -r1.62 konq_frame.h
--- konq_frame.h 2001/03/06 22:40:19 1.62
+++ konq_frame.h 2001/05/09 21:00:28
@@ -33,7 +33,10 @@
class QPixmap;
class QVBoxLayout;
+class QHBoxLayout;
class QTimer;
+class QPushButton;
+
class KonqView;
class KonqFrameBase;
class KonqFrame;
@@ -41,6 +44,7 @@ class KonqFrameContainer;
class KConfig;
class KSeparator;
class KProgress;
+class KAction;
namespace KParts
{
@@ -124,6 +128,34 @@ class KonqFrameStatusBar : public QWidge
QString m_savedMessage;
};
+
+/**
+ * The KonqFrameHeader provides a title and button to remove the view.
+ */
+
+class KonqFrameHeader : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ KonqFrameHeader( KonqFrame *_parent = 0L, const char *_name = 0L );
+ virtual ~KonqFrameHeader();
+ virtual void setAction( KAction *inAction );
+ virtual bool eventFilter(QObject *obj, QEvent *ev);
+
+ public slots:
+ void slotConnectToNewView(KonqView *, KParts::ReadOnlyPart \
*oldOne,KParts::ReadOnlyPart *newOne); + void slotSetHeaderText(const QString& \
text); + void slotDoAction();
+ protected:
+
+ KonqFrame* m_pParentKonqFrame;
+ QLabel *m_pHeaderLabel;
+ QPushButton *m_pCloseButton;
+ QHBoxLayout *m_pLayout;
+ KAction *m_pAction;
+};
+
typedef QList<KonqView> ChildViewList;
class KonqFrameBase
@@ -178,7 +210,7 @@ public:
make KonqMainWindow switch to the next view
*/
virtual bool eventFilter(QObject*obj,QEvent *ev);
-
+
/**
* Inserts the part's widget and the statusbar into the layout
*/
@@ -217,6 +249,7 @@ public:
QVBoxLayout *layout() { return m_pLayout; }
KonqFrameStatusBar *statusbar() const { return m_pStatusBar; }
+ KonqFrameHeader *header() const { return m_pHeader; }
public slots:
@@ -242,6 +275,7 @@ protected:
KSeparator *m_separator;
KonqFrameStatusBar* m_pStatusBar;
+ KonqFrameHeader *m_pHeader;
};
/**
Index: konq_guiclients.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_guiclients.cc,v
retrieving revision 1.35
diff -u -3 -p -r1.35 konq_guiclients.cc
--- konq_guiclients.cc 2000/12/15 23:20:28 1.35
+++ konq_guiclients.cc 2001/05/09 21:00:28
@@ -284,13 +284,13 @@ void ToggleViewGUIClient::saveConfig( bo
void ToggleViewGUIClient::slotViewAdded( KonqView *view )
{
QString name = view->service()->desktopEntryName();
-
KAction *action = m_actions[ name ];
if ( action )
{
static_cast<KToggleAction *>( action )->setChecked( true );
saveConfig( true, name );
+ view->frame()->header()->setAction(action);
}
}
Index: dirtree/konq_treepart.cpp
===================================================================
RCS file: /home/kde/kdebase/konqueror/dirtree/konq_treepart.cpp,v
retrieving revision 1.8
diff -u -3 -p -r1.8 konq_treepart.cpp
--- dirtree/konq_treepart.cpp 2001/01/14 12:51:39 1.8
+++ dirtree/konq_treepart.cpp 2001/05/09 21:00:28
@@ -137,10 +137,16 @@ KonqTreePart::KonqTreePart( QWidget *par
setWidget( m_pTree );
setInstance( KonqTreeFactory::instance(), false );
m_url.setPath( QDir::homeDirPath() );
+ QTimer::singleShot(0, this, SLOT(setTitle()));
}
KonqTreePart::~KonqTreePart()
{
+}
+
+void KonqTreePart::setTitle()
+{
+ m_pTree->setCaption(" Sidebar ");
}
bool KonqTreePart::openURL( const KURL & url )
Index: dirtree/konq_treepart.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/dirtree/konq_treepart.h,v
retrieving revision 1.4
diff -u -3 -p -r1.4 konq_treepart.h
--- dirtree/konq_treepart.h 2001/01/14 12:51:39 1.4
+++ dirtree/konq_treepart.h 2001/05/09 21:00:28
@@ -96,6 +96,9 @@ public:
void emitStatusBarText( const QString& text );
+public slots:
+ void setTitle();
+
private:
KonqTreeBrowserExtension * m_extension;
KonqTree * m_pTree;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic