00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include "guiclient.h"
00022
#include "guiclient.moc"
00023
00024
#include <qpopupmenu.h>
00025
#include <kapplication.h>
00026
#include <kconfig.h>
00027
#include <ktoolbar.h>
00028
#include <klocale.h>
00029
#include <kaction.h>
00030
#include <qstring.h>
00031
#include <kdebug.h>
00032
#include <kdockwidget.h>
00033
00034
#include "mainwindow.h"
00035
#include "toolviewaccessor.h"
00036
#include "toolviewaccessor_p.h"
00037
00038
static const char *actionListName =
"show_kmdi_document_tool_view_actions";
00039
00040
static const char *guiDescription =
""
00041
"<!DOCTYPE kpartgui><kpartgui name=\"KMDIViewActions\">"
00042
"<MenuBar>"
00043
" <Menu name=\"window\">"
00044
" <ActionList name=\"%1\" />"
00045
" </Menu>"
00046
"</MenuBar>"
00047
"</kpartgui>";
00048
00049
static const char *resourceFileName =
"kmdiviewactions.rc";
00050
00051
namespace KMDIPrivate
00052 {
00053
00054 GUIClient::GUIClient (KMDI::MainWindow* mdiMainFrm,
const char* name)
00055 :
QObject ( mdiMainFrm,name )
00056 , KXMLGUIClient ( mdiMainFrm )
00057 {
00058 m_mdiMainFrm=mdiMainFrm;
00059
00060 connect( mdiMainFrm->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ),
00061
this, SLOT( clientAdded( KXMLGUIClient * ) ) );
00062
00063
00064
00065
00066
00067
00068
00069
if ( domDocument().documentElement().isNull() )
00070 {
00071
QString completeDescription = QString::fromLatin1( guiDescription ).arg( actionListName );
00072
00073 setXML( completeDescription,
false );
00074 }
00075
00076
if (actionCollection()->kaccel()==0)
00077 actionCollection()->setWidget(mdiMainFrm);
00078
00079 m_toolMenu=
new KActionMenu(i18n(
"Tool &Views"),actionCollection(),
"kmdi_toolview_menu");
00080
00081 m_gotoToolDockMenu=
new KActionMenu(i18n(
"Tool &Docks"),actionCollection(),
"kmdi_tooldock_menu");
00082 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Switch Top Dock"),ALT+CTRL+SHIFT+Key_T,
this,SIGNAL(toggleTop()),
00083 actionCollection(),
"kmdi_activate_top"));
00084 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Switch Left Dock"),ALT+CTRL+SHIFT+Key_L,
this,SIGNAL(toggleLeft()),
00085 actionCollection(),
"kmdi_activate_left"));
00086 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Switch Right Dock"),ALT+CTRL+SHIFT+Key_R,
this,SIGNAL(toggleRight()),
00087 actionCollection(),
"kmdi_activate_right"));
00088 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Switch Bottom Dock"),ALT+CTRL+SHIFT+Key_B,
this,SIGNAL(toggleBottom()),
00089 actionCollection(),
"kmdi_activate_bottom"));
00090 m_gotoToolDockMenu->insert(
new KActionSeparator(actionCollection(),
"kmdi_goto_menu_separator"));
00091 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Previous Tool View"),ALT+CTRL+Key_Left,m_mdiMainFrm,SLOT(prevToolViewInDock()),
00092 actionCollection(),
"kmdi_prev_toolview"));
00093 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Next Tool View"),ALT+CTRL+Key_Right,m_mdiMainFrm,SLOT(nextToolViewInDock()),
00094 actionCollection(),
"kmdi_next_toolview"));
00095
00096 actionCollection()->readShortcutSettings(
"Shortcuts", kapp->config() );
00097 }
00098
00099 GUIClient::~GUIClient()
00100 {
00101
00102
for (uint i=0;i<m_toolViewActions.count();i++)
00103 disconnect(m_toolViewActions.at(i),0,
this,0);
00104
00105 m_toolViewActions.setAutoDelete(
false );
00106 m_toolViewActions.clear();
00107 m_documentViewActions.setAutoDelete(
false );
00108 m_documentViewActions.clear();
00109 }
00110
00111
void GUIClient::setupActions()
00112 {
00113
if ( !factory() || !m_mdiMainFrm )
00114
return;
00115
00116 unplugActionList( actionListName );
00117
00118
QPtrList<KAction> addList;
00119
if (m_toolViewActions.count()<3)
00120 {
00121
for (uint i=0;i<m_toolViewActions.count();i++)
00122 addList.append(m_toolViewActions.at(i));
00123 }
00124
else
00125 addList.append(m_toolMenu);
00126
00127 addList.append(m_gotoToolDockMenu);
00128
00129 kdDebug(760)<<
"GUIClient::setupActions: plugActionList"<<endl;
00130
00131 plugActionList( actionListName, addList );
00132 }
00133
00134
void GUIClient::addToolView(KMDI::ToolViewAccessor* mtva)
00135 {
00136 kdDebug(760)<<
"*****void GUIClient::addToolView(KMDI::ToolViewAccessor* mtva)*****"<<endl;
00137
00138
QString aname =
QString(
"kmdi_toolview_") + mtva->wrappedWidget()->name();
00139
00140
00141 KShortcut sc;
00142 KConfig *cfg = kapp->config();
00143 QString _grp = cfg->group();
00144 cfg->setGroup(
"Shortcuts");
00145 sc = KShortcut( cfg->readEntry( aname,
"" ) );
00146 cfg->setGroup( _grp );
00147
00148 KAction *a=
new ToggleToolViewAction(i18n(
"Show %1").arg(mtva->wrappedWidget()->caption()),
00149 sc,dynamic_cast<KDockWidget*>(mtva->wrapperWidget()),
00150 m_mdiMainFrm,actionCollection(), aname.latin1() );
00151
00152 ((ToggleToolViewAction*)a)->setCheckedState(i18n(
"Hide %1").arg(mtva->wrappedWidget()->caption()));
00153
00154 connect(a,SIGNAL(destroyed(
QObject*)),
this,SLOT(actionDeleted(
QObject*)));
00155
00156 m_toolViewActions.append(a);
00157 m_toolMenu->insert(a);
00158 mtva->d->action=a;
00159
00160 setupActions();
00161 }
00162
00163
void GUIClient::actionDeleted(
QObject* a)
00164 {
00165 m_toolViewActions.remove(static_cast<KAction*>(a));
00166 setupActions();
00167 }
00168
00169
00170
void GUIClient::clientAdded( KXMLGUIClient *client )
00171 {
00172
if ( client ==
this )
00173 setupActions();
00174 }
00175
00176 ToggleToolViewAction::ToggleToolViewAction (
const QString& text,
const KShortcut& cut,KDockWidget *dw, KMDI::MainWindow *mdiMainFrm,
00177
QObject* parent,
const char* name )
00178 : KToggleAction(text,cut,parent,name)
00179 , m_dw(dw)
00180 , m_mdiMainFrm(mdiMainFrm)
00181 {
00182
if (m_dw)
00183 {
00184 connect(
this,SIGNAL(toggled(
bool)),
this,SLOT(slotToggled(
bool)));
00185 connect(m_dw->dockManager(),SIGNAL(change()),
this,SLOT(anDWChanged()));
00186 connect(m_dw,SIGNAL(destroyed()),
this,SLOT(slotWidgetDestroyed()));
00187
00188 setChecked(m_dw->mayBeHide());
00189 }
00190 }
00191
00192 ToggleToolViewAction::~ToggleToolViewAction()
00193 {
00194 unplugAll();
00195 }
00196
00197
void ToggleToolViewAction::anDWChanged()
00198 {
00199
if (isChecked() && m_dw->mayBeShow())
00200 setChecked(
false);
00201
else if ((!isChecked()) && m_dw->mayBeHide())
00202 setChecked(
true);
00203
else if (isChecked() && (m_dw->parentDockTabGroup() &&
00204 ((static_cast<KDockWidget*>(m_dw->parentDockTabGroup()->
00205 parent()->qt_cast(
"KDockWidget")))->mayBeShow())))
00206 setChecked(
false);
00207 }
00208
00209
00210
void ToggleToolViewAction::slotToggled(
bool t)
00211 {
00212
if ((!t) && m_dw->mayBeHide() )
00213 m_dw->undock();
00214
else
00215
if ( t && m_dw->mayBeShow() )
00216 m_mdiMainFrm->makeDockVisible(m_dw);
00217 }
00218
00219
void ToggleToolViewAction::slotWidgetDestroyed()
00220 {
00221 disconnect(m_dw->dockManager(),SIGNAL(change()),
this,SLOT(anDWChanged()));
00222 disconnect(
this,SIGNAL(toggled(
bool)),0,0);
00223
00224 unplugAll();
00225 deleteLater();
00226 }
00227
00228 }
00229
00230