kparts: drop status bar extension

other than setting the status bar text no other feature functions
properly and there is a signal to change the part window status bar
text thus the class is redundant

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-31 05:05:16 +03:00
parent ab09380d5b
commit 41631e5960
5 changed files with 0 additions and 322 deletions

View file

@ -394,7 +394,6 @@ install(
KParts/PartBase KParts/PartBase
KParts/ReadOnlyPart KParts/ReadOnlyPart
KParts/ReadWritePart KParts/ReadWritePart
KParts/StatusBarExtension
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/KDE/KParts DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/KDE/KParts
) )

View file

@ -1 +0,0 @@
#include "../../kparts/statusbarextension.h"

View file

@ -17,7 +17,6 @@ set(kparts_LIB_SRCS
mainwindow.cpp mainwindow.cpp
event.cpp event.cpp
factory.cpp factory.cpp
statusbarextension.cpp
) )
add_library(kparts SHARED ${kparts_LIB_SRCS}) add_library(kparts SHARED ${kparts_LIB_SRCS})
@ -58,6 +57,5 @@ install(
mainwindow.h mainwindow.h
event.h event.h
factory.h factory.h
statusbarextension.h
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/kparts DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/kparts
) )

View file

@ -1,193 +0,0 @@
/* This file is part of the KDE project
Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org>
Copyright (C) 2003 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "statusbarextension.h"
#include <QtCore/QObject>
#include <kstatusbar.h>
#include <kmainwindow.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kparts/part.h>
#include <kparts/event.h>
using namespace KParts;
///////////////////////////////////////////////////////////////////
// Helper Classes
///////////////////////////////////////////////////////////////////
class KParts::StatusBarItem {
public:
StatusBarItem() // for QValueList
: m_widget(0), m_visible(false)
{}
StatusBarItem( QWidget * widget, int stretch, bool permanent )
: m_widget(widget), m_stretch(stretch), m_permanent(permanent), m_visible(false)
{}
QWidget * widget() const { return m_widget; }
void ensureItemShown( KStatusBar * sb )
{
if ( m_widget && !m_visible )
{
if ( m_permanent )
sb->addPermanentWidget( m_widget, m_stretch );
else
sb->addWidget( m_widget, m_stretch );
m_visible = true;
m_widget->show();
}
}
void ensureItemHidden( KStatusBar * sb )
{
if ( m_widget && m_visible )
{
sb->removeWidget( m_widget );
m_visible = false;
m_widget->hide();
}
}
private:
QPointer<QWidget> m_widget;
int m_stretch;
bool m_permanent;
bool m_visible; // true when the item has been added to the statusbar
};
class KParts::StatusBarExtensionPrivate
{
public:
StatusBarExtensionPrivate(StatusBarExtension *q): q(q),
m_statusBar(0),
m_activated(true) {}
StatusBarExtension *q;
QList<StatusBarItem> m_statusBarItems; // Our statusbar items
KStatusBar* m_statusBar;
bool m_activated;
};
///////////////////////////////////////////////////////////////////
StatusBarExtension::StatusBarExtension(KParts::ReadOnlyPart *parent)
: QObject(parent), d(new StatusBarExtensionPrivate(this))
{
parent->installEventFilter(this);
}
StatusBarExtension::~StatusBarExtension()
{
KStatusBar * sb = d->m_statusBar;
for ( int i = d->m_statusBarItems.count () - 1; i >= 0 ; --i ) {
if ( d->m_statusBarItems[i].widget() ) {
if ( sb ) {
d->m_statusBarItems[i].ensureItemHidden( sb );
}
d->m_statusBarItems[i].widget()->deleteLater();
}
}
delete d;
}
StatusBarExtension *StatusBarExtension::childObject( QObject *obj )
{
return KGlobal::findDirectChild<KParts::StatusBarExtension*>(obj);
}
bool StatusBarExtension::eventFilter(QObject * watched, QEvent* ev)
{
if ( !GUIActivateEvent::test( ev ) ||
!qobject_cast<KParts::ReadOnlyPart *>(watched) )
return QObject::eventFilter(watched, ev);
KStatusBar * sb = statusBar();
if ( !sb )
return QObject::eventFilter(watched, ev);
GUIActivateEvent *gae = static_cast<GUIActivateEvent*>(ev);
d->m_activated = gae->activated();
if ( d->m_activated )
{
QList<StatusBarItem>::iterator it = d->m_statusBarItems.begin();
for ( ; it != d->m_statusBarItems.end() ; ++it )
(*it).ensureItemShown( sb );
}
else
{
QList<StatusBarItem>::iterator it = d->m_statusBarItems.begin();
for ( ; it != d->m_statusBarItems.end() ; ++it )
(*it).ensureItemHidden( sb );
}
return false;
}
KStatusBar * StatusBarExtension::statusBar() const
{
if ( !d->m_statusBar ) {
KParts::ReadOnlyPart* part = qobject_cast<KParts::ReadOnlyPart*>(parent());
QWidget* w = part ? part->widget() : 0;
KMainWindow* mw = w ? qobject_cast<KMainWindow *>( w->window() ) : 0;
if ( mw )
d->m_statusBar = mw->statusBar();
}
return d->m_statusBar;
}
void StatusBarExtension::setStatusBar( KStatusBar* status )
{
d->m_statusBar = status;
}
void StatusBarExtension::addStatusBarItem( QWidget * widget, int stretch, bool permanent )
{
d->m_statusBarItems.append( StatusBarItem( widget, stretch, permanent ) );
StatusBarItem& it = d->m_statusBarItems.last();
KStatusBar * sb = statusBar();
if (sb && d->m_activated)
it.ensureItemShown( sb );
}
void StatusBarExtension::removeStatusBarItem( QWidget * widget )
{
KStatusBar * sb = statusBar();
QList<StatusBarItem>::iterator it = d->m_statusBarItems.begin();
for ( ; it != d->m_statusBarItems.end() ; ++it )
if ( (*it).widget() == widget )
{
if ( sb )
(*it).ensureItemHidden( sb );
d->m_statusBarItems.erase( it );
return;
}
kWarning() << "StatusBarExtension::removeStatusBarItem. Widget not found : " << widget;
}
#include "moc_statusbarextension.cpp"
// vim: ts=2 sw=2 et

View file

@ -1,125 +0,0 @@
/* This file is part of the KDE project
Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org>
Copyright (C) 2003 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KPARTS_STATUSBAREXTENSION_H
#define KPARTS_STATUSBAREXTENSION_H
#include <QtGui/QWidget>
#include <QtCore/QList>
#include <QEvent>
#include <kparts/kparts_export.h>
class KStatusBar;
class KMainWindow;
namespace KParts
{
class ReadOnlyPart;
// Defined in impl
class StatusBarItem;
class StatusBarExtensionPrivate;
/**
* @short an extension for KParts that allows more sophisticated statusbar handling
*
* Every part can use this class to customize the statusbar as long as it is active.
* Add items via addStatusBarItem and remove an item with removeStatusBarItem.
*
* IMPORTANT: do NOT add any items immediately after constructing the extension.
* Give the application time to set the statusbar in the extension if necessary.
*/
class KPARTS_EXPORT StatusBarExtension : public QObject
{
Q_OBJECT
public:
StatusBarExtension( KParts::ReadOnlyPart *parent );
~StatusBarExtension();
/**
* This adds a widget to the statusbar for this part.
* If you use this method instead of using statusBar() directly,
* this extension will take care of removing the items when the parts GUI
* is deactivated and will re-add them when it is reactivated.
* The parameters are the same as QStatusBar::addWidget().
*
* Note that you can't use KStatusBar methods (inserting text items by id)
* but you can create a KStatusBarLabel with a dummy id instead, and use
* it directly in order to get the same look and feel.
*
* @param widget the widget to add
* @param stretch the stretch factor. 0 for a minimum size.
* @param permanent passed to QStatusBar::addWidget as the "permanent" bool.
* Note that the item isn't really permanent though, it goes away when
* the part is unactivated. This simply controls where temporary messages
* hide the @p widget, and whether it's added to the left or to the right side.
*
* @Note that the widget does not technically become a child of the
* StatusBarExtension in a QObject sense. However, it @em will be deleted
* when the StatusBarExtension is deleted.
*
* IMPORTANT: do NOT add any items immediately after constructing the extension.
* Give the application time to set the statusbar in the extension if necessary.
*/
void addStatusBarItem( QWidget * widget, int stretch, bool permanent );
/**
* Remove a widget from the statusbar for this part.
*/
void removeStatusBarItem( QWidget * widget );
/**
* @return the statusbar of the KMainWindow in which this part is currently embedded.
* WARNING: this could return 0L
*/
KStatusBar* statusBar() const;
/**
* This allows the hosting application to set a particular KStatusBar
* for this part. If it doesn't do this, the statusbar used will be
* the one of the KMainWindow in which the part is embedded.
* Konqueror uses this to assign a view-statusbar to the part.
* The part should never call this method!
*/
void setStatusBar( KStatusBar* status );
/**
* Queries @p obj for a child object which inherits StatusBarExtension
* class. Convenience method.
*/
static StatusBarExtension *childObject( QObject *obj );
/** @internal */
virtual bool eventFilter( QObject *watched, QEvent* ev );
private:
// for future extensions
friend class StatusBarExtensionPrivate;
StatusBarExtensionPrivate* const d;
};
}
#endif // KPARTS_STATUSBAREXTENSION_H
// vim: ts=2 sw=2 et