00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kmdiguiclient.h"
00021
#include "kmdiguiclient.moc"
00022
00023
#include <qpopupmenu.h>
00024
#include <kapplication.h>
00025
#include <kconfig.h>
00026
#include <ktoolbar.h>
00027
#include <kmainwindow.h>
00028
#include <klocale.h>
00029
#include <kaction.h>
00030
#include <qstring.h>
00031
#include <assert.h>
00032
#include <kdebug.h>
00033
#include <kdockwidget.h>
00034
#include <kdeversion.h>
00035
#include "kmdimainfrm.h"
00036
#include "kmditoolviewaccessor.h"
00037
#include "kmditoolviewaccessor_p.h"
00038
namespace
00039
{
00040
const char *actionListName =
"show_kmdi_document_tool_view_actions";
00041
00042
const char *guiDescription =
""
00043
"<!DOCTYPE kpartgui><kpartgui name=\"KMDIViewActions\">"
00044
"<MenuBar>"
00045
" <Menu name=\"view\">"
00046
" <ActionList name=\"%1\" />"
00047
" </Menu>"
00048
"</MenuBar>"
00049
"</kpartgui>";
00050
00051
const char *resourceFileName =
"kmdiviewactions.rc";
00052
00053 }
00054
00055
00056
using namespace KMDIPrivate;
00057
00058
00059
00060 ToggleToolViewAction::ToggleToolViewAction(
const QString& text,
const KShortcut& cut,KDockWidget *dw,
KMdiMainFrm *mdiMainFrm,
00061
QObject* parent,
const char* name )
00062 :KToggleAction(text,cut,parent,name),m_dw(dw),m_mdiMainFrm(mdiMainFrm)
00063 {
00064
if (m_dw) {
00065 connect(
this,SIGNAL(toggled(
bool)),
this,SLOT(slotToggled(
bool)));
00066 connect(m_dw->dockManager(),SIGNAL(change()),
this,SLOT(anDWChanged()));
00067 connect(m_dw,SIGNAL(destroyed()),
this,SLOT(slotWidgetDestroyed()));
00068 setChecked(m_dw->mayBeHide());
00069 }
00070 }
00071
00072
00073 ToggleToolViewAction::~ToggleToolViewAction(){unplugAll();}
00074
00075
void ToggleToolViewAction::anDWChanged()
00076 {
00077
if (isChecked() && m_dw->mayBeShow()) setChecked(
false);
00078
else if ((!isChecked()) && m_dw->mayBeHide()) setChecked(
true);
00079
else if (isChecked() && (m_dw->parentDockTabGroup() &&
00080 ((static_cast<KDockWidget*>(m_dw->parentDockTabGroup()->
00081 parent()->qt_cast(
"KDockWidget")))->mayBeShow()))) setChecked(
false);
00082 }
00083
00084
00085
void ToggleToolViewAction::slotToggled(
bool t)
00086 {
00087
00088
00089
if ((!t) && m_dw->mayBeHide() ) m_dw->undock();
00090
else
00091
if ( t && m_dw->mayBeShow() ) m_mdiMainFrm->makeDockVisible(m_dw);
00092
00093
00094 }
00095
00096
void ToggleToolViewAction::slotWidgetDestroyed()
00097 {
00098 disconnect(m_dw->dockManager(),SIGNAL(change()),
this,SLOT(anDWChanged()));
00099 disconnect(
this,SIGNAL(toggled(
bool)),0,0);
00100 unplugAll();
00101 deleteLater();
00102 }
00103
00104
00105 KMDIGUIClient::KMDIGUIClient(
KMdiMainFrm* mdiMainFrm,
bool showMDIModeAction,
const char* name):
QObject( mdiMainFrm,name ),
00106 KXMLGUIClient( mdiMainFrm )
00107 {
00108 m_mdiMode=KMdi::ChildframeMode;
00109 m_mdiMainFrm=mdiMainFrm;
00110 connect( mdiMainFrm->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ),
00111
this, SLOT( clientAdded( KXMLGUIClient * ) ) );
00112
00113
00114
00115
00116
00117
00118
00119
if ( domDocument().documentElement().isNull() ) {
00120
00121
QString completeDescription = QString::fromLatin1( guiDescription )
00122 .arg( actionListName );
00123
00124 setXML( completeDescription,
false );
00125 }
00126
00127
if (actionCollection()->kaccel()==0)
00128 actionCollection()->setWidget(mdiMainFrm);
00129 m_toolMenu=
new KActionMenu(i18n(
"Tool &Views"),actionCollection(),
"kmdi_toolview_menu");
00130
if (showMDIModeAction) {
00131 m_mdiModeAction=
new KSelectAction(i18n(
"MDI Mode"),0,actionCollection());
00132
QStringList modes;
00133 modes<<i18n(
"&Toplevel Mode")<<i18n(
"C&hildframe Mode")<<i18n(
"Ta&b Page Mode")<<i18n(
"I&DEAl Mode");
00134 m_mdiModeAction->setItems(modes);
00135 connect(m_mdiModeAction,SIGNAL(activated(
int)),
this,SLOT(changeViewMode(
int)));
00136 }
else m_mdiModeAction=0;
00137
00138 connect(m_mdiMainFrm,SIGNAL(mdiModeHasBeenChangedTo(KMdi::MdiMode)),
00139
this,SLOT(mdiModeHasBeenChangedTo(KMdi::MdiMode)));
00140
00141 m_gotoToolDockMenu=
new KActionMenu(i18n(
"Tool &Docks"),actionCollection(),
"kmdi_tooldock_menu");
00142 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Switch Top Dock"),ALT+CTRL+SHIFT+Key_T,
this,SIGNAL(toggleTop()),
00143 actionCollection(),
"kmdi_activate_top"));
00144 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Switch Left Dock"),ALT+CTRL+SHIFT+Key_L,
this,SIGNAL(toggleLeft()),
00145 actionCollection(),
"kmdi_activate_left"));
00146 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Switch Right Dock"),ALT+CTRL+SHIFT+Key_R,
this,SIGNAL(toggleRight()),
00147 actionCollection(),
"kmdi_activate_right"));
00148 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Switch Bottom Dock"),ALT+CTRL+SHIFT+Key_B,
this,SIGNAL(toggleBottom()),
00149 actionCollection(),
"kmdi_activate_bottom"));
00150 m_gotoToolDockMenu->insert(
new KActionSeparator(actionCollection(),
"kmdi_goto_menu_separator"));
00151 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Previous Tool View"),ALT+CTRL+Key_Left,m_mdiMainFrm,SLOT(prevToolViewInDock()),
00152 actionCollection(),
"kmdi_prev_toolview"));
00153 m_gotoToolDockMenu->insert(
new KAction(i18n(
"Next Tool View"),ALT+CTRL+Key_Right,m_mdiMainFrm,SLOT(nextToolViewInDock()),
00154 actionCollection(),
"kmdi_next_toolview"));
00155
00156 actionCollection()->readShortcutSettings(
"Shortcuts", kapp->config() );
00157 }
00158
00159 KMDIGUIClient::~KMDIGUIClient()
00160 {
00161
00162
00163
for (uint i=0;i<m_toolViewActions.count();i++)
00164 disconnect(m_toolViewActions.at(i),0,
this,0);
00165
00166 m_toolViewActions.setAutoDelete(
false );
00167 m_toolViewActions.clear();
00168 m_documentViewActions.setAutoDelete(
false );
00169 m_documentViewActions.clear();
00170 }
00171
00172
void KMDIGUIClient::changeViewMode(
int id) {
00173
switch (
id) {
00174
case 0: m_mdiMainFrm->switchToToplevelMode();
00175
break;
00176
case 1: m_mdiMainFrm->switchToChildframeMode();
00177
break;
00178
case 2: m_mdiMainFrm->switchToTabPageMode();
00179
break;
00180
case 3: m_mdiMainFrm->switchToIDEAlMode();
00181
break;
00182
default:
00183 Q_ASSERT(0);
00184 }
00185 }
00186
00187
void KMDIGUIClient::setupActions()
00188 {
00189
if ( !factory() || !m_mdiMainFrm )
00190
return;
00191
00192
00193
00194
00195
00196
00197
00198 unplugActionList( actionListName );
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
QPtrList<KAction> addList;
00212
if (m_toolViewActions.count()<3)
00213
for (uint i=0;i<m_toolViewActions.count();i++)
00214 addList.append(m_toolViewActions.at(i));
00215
else
00216 addList.append(m_toolMenu);
00217
if (m_mdiMode==KMdi::IDEAlMode) addList.append(m_gotoToolDockMenu);
00218
if (m_mdiModeAction) addList.append(m_mdiModeAction);
00219 kdDebug(760)<<
"KMDIGUIClient::setupActions: plugActionList"<<endl;
00220 plugActionList( actionListName, addList );
00221
00222
00223 }
00224
00225
void KMDIGUIClient::addToolView(KMdiToolViewAccessor* mtva) {
00226 kdDebug(760)<<
"*****void KMDIGUIClient::addToolView(KMdiToolViewAccessor* mtva)*****"<<endl;
00227
00228
QString aname =
QString(
"kmdi_toolview_") + mtva->wrappedWidget()->name();
00229
00230
00231 KShortcut sc;
00232 KConfig *cfg = kapp->config();
00233
QString _grp = cfg->group();
00234 cfg->setGroup(
"Shortcuts");
00235
00236 sc = KShortcut( cfg->readEntry( aname,
"" ) );
00237 cfg->setGroup( _grp );
00238 KAction *a=
new ToggleToolViewAction(i18n(
"Show %1").arg(mtva->wrappedWidget()->caption()),
00239 sc,dynamic_cast<KDockWidget*>(mtva->wrapperWidget()),
00240 m_mdiMainFrm,actionCollection(), aname.latin1() );
00241
#if KDE_IS_VERSION(3,2,90)
00242
((ToggleToolViewAction*)a)->setCheckedState(i18n(
"Hide %1").arg(mtva->wrappedWidget()->caption()));
00243
#endif
00244
connect(a,SIGNAL(destroyed(
QObject*)),
this,SLOT(actionDeleted(
QObject*)));
00245 m_toolViewActions.append(a);
00246 m_toolMenu->insert(a);
00247 mtva->d->action=a;
00248
00249 setupActions();
00250 }
00251
00252
void KMDIGUIClient::actionDeleted(
QObject* a) {
00253 m_toolViewActions.remove(static_cast<KAction*>(a));
00254
00255 setupActions();
00256 }
00257
00258
00259
void KMDIGUIClient::clientAdded( KXMLGUIClient *client )
00260 {
00261
if ( client ==
this )
00262 setupActions();
00263 }
00264
00265
00266
void KMDIGUIClient::mdiModeHasBeenChangedTo(KMdi::MdiMode mode) {
00267 kdDebug(760)<<
"KMDIGUIClient::mdiModeHasBennChangeTo"<<endl;
00268 m_mdiMode=mode;
00269
if (m_mdiModeAction) {
00270
switch (mode) {
00271
case KMdi::ToplevelMode:
00272 m_mdiModeAction->setCurrentItem(0);
00273
break;
00274
case KMdi::ChildframeMode:
00275 m_mdiModeAction->setCurrentItem(1);
00276
break;
00277
case KMdi::TabPageMode:
00278 m_mdiModeAction->setCurrentItem(2);
00279
break;
00280
case KMdi::IDEAlMode:
00281 m_mdiModeAction->setCurrentItem(3);
00282
break;
00283
default: Q_ASSERT(0);
00284 }
00285 }
00286 setupActions();
00287
00288 }
00289
00290
00291