You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
395 lines
9.6 KiB
395 lines
9.6 KiB
15 years ago
|
%{CPP_TEMPLATE}
|
||
|
|
||
14 years ago
|
#include <tqdragobject.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqpaintdevicemetrics.h>
|
||
|
#include <tqdragobject.h>
|
||
14 years ago
|
#include <statusbar.h>
|
||
14 years ago
|
#include <tqtoolbutton.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
#include <kglobal.h>
|
||
|
#include <ktip.h>
|
||
12 years ago
|
#include <tdeparts/part.h>
|
||
|
#include <tdeparts/partmanager.h>
|
||
15 years ago
|
|
||
|
#include <kio/netaccess.h>
|
||
|
#include <kurl.h>
|
||
|
#include <kurldrag.h>
|
||
|
#include <kurlrequesterdlg.h>
|
||
|
#include <kconfig.h>
|
||
|
#include <kconfigdialog.h>
|
||
|
#include <klibloader.h>
|
||
|
#include <kaboutdata.h>
|
||
|
#include <kfiledialog.h>
|
||
|
#include <kactionclasses.h>
|
||
|
#include <kglobal.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kiconloader.h>
|
||
13 years ago
|
#include <tdeversion.h>
|
||
15 years ago
|
#include <kmenubar.h>
|
||
|
#include <kstatusbar.h>
|
||
|
#include <kkeydialog.h>
|
||
|
#include <kmessagebox.h>
|
||
|
#include <ktabwidget.h>
|
||
|
#include <kedittoolbar.h>
|
||
13 years ago
|
#include <tdeversion.h>
|
||
15 years ago
|
#include <kstdaccel.h>
|
||
|
#include <kaction.h>
|
||
|
#include <kstdaction.h>
|
||
|
|
||
|
#include "settings.h"
|
||
|
#include "prefs.h"
|
||
12 years ago
|
#include "%{APPNAMELC}tdemdiView.h"
|
||
|
#include "tdemdikonsole.h"
|
||
|
#include "%{APPNAMELC}tdemdi.h"
|
||
15 years ago
|
|
||
12 years ago
|
%{APPNAMELC}tdemdi::%{APPNAMELC}tdemdi(KMdi::MdiMode mode)
|
||
15 years ago
|
: KMdiMainFrm( 0, "%{APPNAMELC}", mode )
|
||
|
{
|
||
|
resize( 800, 600 ); // start at 800x600 the first time
|
||
|
|
||
|
setManagedDockPositionModeEnabled(true);
|
||
|
setStandardMDIMenuEnabled(false);
|
||
|
|
||
|
m_manager = new KParts::PartManager(this);
|
||
14 years ago
|
connect(m_manager, TQT_SIGNAL(activePartChanged(KParts::Part*)),
|
||
|
this, TQT_SLOT(createGUI(KParts::Part*)) );
|
||
15 years ago
|
|
||
|
#if KDE_IS_VERSION(3, 3, 0)
|
||
|
setToolviewStyle( KMdi::TextAndIcon );
|
||
|
tabWidget()->setHoverCloseButton( false );
|
||
|
#endif
|
||
|
|
||
|
setMenuForSDIModeSysButtons( menuBar() );
|
||
|
setManagedDockPositionModeEnabled(true);
|
||
|
|
||
|
m_console = NULL;
|
||
|
|
||
|
// accept dnd
|
||
|
setAcceptDrops(true);
|
||
|
|
||
|
// then, setup our actions
|
||
|
setupActions();
|
||
|
|
||
|
//createShellGUI( true );
|
||
|
|
||
|
// and a status bar
|
||
|
statusBar()->show();
|
||
|
|
||
14 years ago
|
connect( this, TQT_SIGNAL( viewActivated( KMdiChildView * ) ), this, TQT_SLOT( currentChanged( KMdiChildView * ) ) );
|
||
15 years ago
|
|
||
12 years ago
|
m_console = new tdemdikonsole(this, "konsole");
|
||
15 years ago
|
m_console->setIcon( SmallIcon("konsole") );
|
||
|
m_console->setCaption( i18n("Terminal") );
|
||
|
addToolWindow( m_console, KDockWidget::DockBottom, getMainDockWidget(), 20 );
|
||
|
|
||
|
|
||
|
#if KDE_IS_VERSION(3, 3, 0)
|
||
|
if (Settings::showCloseTabsButton())
|
||
|
{
|
||
14 years ago
|
TQToolButton *but = new TQToolButton(tabWidget());
|
||
15 years ago
|
but->setIconSet(SmallIcon("tab_remove"));
|
||
|
but->adjustSize();
|
||
|
but->hide();
|
||
14 years ago
|
connect(but, TQT_SIGNAL(clicked()), actionCollection()->action( "file_close" ), TQT_SIGNAL(activated()));
|
||
15 years ago
|
tabWidget()->setCornerWidget(but, TopRight);
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
// apply the saved mainwindow settings, if any, and ask the mainwindow
|
||
|
// to automatically save settings if changed: window size, toolbar
|
||
|
// position, icon size, etc.
|
||
|
setAutoSaveSettings();
|
||
|
|
||
12 years ago
|
// Read the dock config only if the app was started at least only once - tdemdi is tricky
|
||
12 years ago
|
TDEConfig *cfg = new TDEConfig("%{APPNAMELC}_dockposrc");
|
||
15 years ago
|
if (cfg->readNumEntry("%{APPNAMELC}_main_dock_settings", 0) == 1) manager()->readConfig(cfg);
|
||
|
cfg->writeEntry("%{APPNAMELC}_main_dock_settings", 1);
|
||
|
delete cfg;
|
||
|
|
||
|
showTipOnStart();
|
||
|
}
|
||
|
|
||
12 years ago
|
%{APPNAMELC}tdemdi::~%{APPNAMELC}tdemdi()
|
||
15 years ago
|
{
|
||
|
// Write the dock config on exit
|
||
12 years ago
|
TDEConfig *cfg = new TDEConfig("%{APPNAMELC}_dockposrc");
|
||
15 years ago
|
manager()->writeConfig(cfg);
|
||
|
delete cfg;
|
||
|
delete m_console;
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::setupActions()
|
||
15 years ago
|
{
|
||
|
setXMLFile("%{APPNAMELC}_shell.rc");
|
||
|
|
||
14 years ago
|
KStdAction::openNew(this, TQT_SLOT(slotFileNew()), actionCollection());
|
||
15 years ago
|
|
||
14 years ago
|
KStdAction::tipOfDay( this, TQT_SLOT( showTip() ), actionCollection()
|
||
15 years ago
|
)->setWhatsThis(i18n("This shows useful tips on the use of this application."));
|
||
|
|
||
14 years ago
|
KStdAction::close(this, TQT_SLOT(slotFileClose()), actionCollection());
|
||
|
KStdAction::quit(this, TQT_SLOT(slotFileQuit()), actionCollection());
|
||
15 years ago
|
|
||
14 years ago
|
m_toolbarAction = KStdAction::showToolbar(this, TQT_SLOT(optionsShowToolbar()), actionCollection());
|
||
|
m_statusbarAction = KStdAction::showStatusbar(this, TQT_SLOT(optionsShowStatusbar()), actionCollection());
|
||
15 years ago
|
|
||
14 years ago
|
KStdAction::keyBindings(this, TQT_SLOT(optionsConfigureKeys()), actionCollection());
|
||
|
KStdAction::preferences(this, TQT_SLOT(optionsPreferences()), actionCollection());
|
||
15 years ago
|
|
||
|
KAction* action = KStdAction::configureToolbars(this,
|
||
14 years ago
|
TQT_SLOT(optionsConfigureToolbars()), actionCollection());
|
||
15 years ago
|
|
||
|
createGUI( NULL );
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::showTip()
|
||
15 years ago
|
{
|
||
14 years ago
|
KTipDialog::showTip(this,TQString(),true);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::showTipOnStart()
|
||
15 years ago
|
{
|
||
|
KTipDialog::showTip(this);
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::slotFileNew()
|
||
15 years ago
|
{
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = new %{APPNAMELC}tdemdiView(this);
|
||
15 years ago
|
m_manager->addPart( view->part() );
|
||
|
|
||
|
addWindow( view );
|
||
|
|
||
|
// add the tree view to the widget stack
|
||
|
m_views += view;
|
||
|
|
||
|
currentChanged( view );
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::openURL(const KURL & url)
|
||
15 years ago
|
{
|
||
|
// check if the url is not already opened first
|
||
12 years ago
|
TQValueList<%{APPNAMELC}tdemdiView*>::iterator it = m_views.begin();
|
||
|
TQValueList<%{APPNAMELC}tdemdiView*>::iterator end = m_views.end();
|
||
15 years ago
|
for (; it != end; ++it)
|
||
|
{
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = *it;
|
||
15 years ago
|
if (view->part()->url() == url)
|
||
|
{
|
||
|
activateView(view);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = new %{APPNAMELC}tdemdiView(this);
|
||
15 years ago
|
m_manager->addPart( view->part() );
|
||
|
|
||
|
addWindow( view );
|
||
|
|
||
|
m_views += view;
|
||
|
|
||
|
view->part()->openURL(url);
|
||
|
currentChanged( view );
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::currentChanged( KMdiChildView *current )
|
||
15 years ago
|
{
|
||
|
//kdWarning()<<"current view changed"<<endl;
|
||
|
if (!current)
|
||
|
{
|
||
|
m_manager->setActivePart(NULL);
|
||
|
//setCaption("()");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// switch to the corresponding document
|
||
12 years ago
|
if ( m_views.contains( (%{APPNAMELC}tdemdiView*) current ) )
|
||
15 years ago
|
{
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = (%{APPNAMELC}tdemdiView*) current;
|
||
15 years ago
|
//view->updateCaption();
|
||
|
m_manager->setActivePart( view->part() );
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::slotFileClose()
|
||
15 years ago
|
{
|
||
|
requestClose( activeWindow() );
|
||
|
}
|
||
|
|
||
12 years ago
|
bool %{APPNAMELC}tdemdi::requestClose(KMdiChildView* v)
|
||
15 years ago
|
{
|
||
|
// kdWarning()<<"closing view"<<v<<endl;
|
||
|
// if (view == NULL)
|
||
|
// return;
|
||
|
|
||
|
if (v == NULL)
|
||
|
{
|
||
|
if ( m_views.count() == 1)
|
||
|
{
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = m_views[0];
|
||
15 years ago
|
if (view->part()->queryClose())
|
||
|
{
|
||
|
m_manager->removePart( view->part() );
|
||
|
|
||
|
closeWindow( view );
|
||
|
m_views.clear();
|
||
|
setCaption("kdissert");
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = (%{APPNAMELC}tdemdiView*) v;
|
||
13 years ago
|
if ( m_views.contains( view ) )
|
||
15 years ago
|
{
|
||
|
m_views.remove( view );
|
||
|
if ( view->part()->queryClose() )
|
||
|
{
|
||
|
m_manager->removePart( view->part() );
|
||
|
|
||
|
closeWindow( view );
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::slotFileQuit()
|
||
15 years ago
|
{
|
||
|
close();
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::optionsShowToolbar()
|
||
15 years ago
|
{
|
||
|
if (m_toolbarAction->isChecked())
|
||
|
toolBar()->show();
|
||
|
else
|
||
|
toolBar()->hide();
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::optionsShowStatusbar()
|
||
15 years ago
|
{
|
||
|
if (m_statusbarAction->isChecked())
|
||
|
statusBar()->show();
|
||
|
else
|
||
|
statusBar()->hide();
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::optionsConfigureKeys()
|
||
15 years ago
|
{
|
||
|
//KKeyDialog::configure(actionCollection());
|
||
|
KKeyDialog dlg( false, this );
|
||
14 years ago
|
TQPtrList<KXMLGUIClient> clients = guiFactory()->clients();
|
||
15 years ago
|
|
||
14 years ago
|
for( TQPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it )
|
||
15 years ago
|
dlg.insert ( (*it)->actionCollection(), (*it)->instance()->aboutData()->programName() );
|
||
|
|
||
|
dlg.configure();
|
||
|
|
||
|
for (int i=0; i<m_views.count(); i++)
|
||
|
{
|
||
|
m_views[i]->part()->reloadXML();
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::optionsConfigureToolbars()
|
||
15 years ago
|
{
|
||
12 years ago
|
//saveMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::newToolbarConfig()
|
||
15 years ago
|
{
|
||
|
// This slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
|
||
|
// recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
|
||
|
//createGUI();
|
||
12 years ago
|
//applyMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::optionsPreferences()
|
||
15 years ago
|
{
|
||
|
// The preference dialog is derived from prefs-base.ui which is subclassed into Prefs
|
||
|
//
|
||
|
// compare the names of the widgets in the .ui file
|
||
|
// to the names of the variables in the .kcfg file
|
||
12 years ago
|
if (TDEConfigDialog::showDialog("settings"))
|
||
15 years ago
|
return;
|
||
|
|
||
12 years ago
|
TDEConfigDialog *dialog = new TDEConfigDialog(this, "settings", Settings::self(), KDialogBase::Swallow);
|
||
15 years ago
|
dialog->addPage(new prefs(), i18n("General"), "package_settings");
|
||
14 years ago
|
connect(dialog, TQT_SIGNAL(settingsChanged()), this, TQT_SLOT(settingsChanged()));
|
||
15 years ago
|
dialog->show();
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::settingsChanged()
|
||
15 years ago
|
{
|
||
|
// propagate the changes to our views
|
||
12 years ago
|
/*TQValueList<%{APPNAMELC}tdemdiView*>::iterator it = m_views.begin();
|
||
|
TQValueList<%{APPNAMELC}tdemdiView*>::iterator end = m_views.end();
|
||
15 years ago
|
for (; it != end; ++it)
|
||
|
{
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = *it;
|
||
15 years ago
|
view->settingsChanged();
|
||
|
}*/
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::changeStatusbar(const TQString& text)
|
||
15 years ago
|
{
|
||
|
// display the text on the statusbar
|
||
|
statusBar()->message(text, 2000);
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::dragEnterEvent(TQDragEnterEvent *event)
|
||
15 years ago
|
{
|
||
|
// accept uri drops only
|
||
|
event->accept(KURLDrag::canDecode(event));
|
||
|
}
|
||
|
|
||
12 years ago
|
void %{APPNAMELC}tdemdi::dropEvent(TQDropEvent *event)
|
||
15 years ago
|
{
|
||
|
KURL::List urls;
|
||
|
|
||
|
// see if we can decode a URI.. if not, just ignore it
|
||
|
if (KURLDrag::decode(event, urls) && !urls.isEmpty())
|
||
|
{
|
||
|
// okay, we have a URI.. process it
|
||
|
const KURL &url = urls.first();
|
||
|
|
||
|
// load in the file
|
||
|
openURL(url);
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
bool %{APPNAMELC}tdemdi::queryClose()
|
||
15 years ago
|
{
|
||
12 years ago
|
TQValueList<%{APPNAMELC}tdemdiView*>::iterator it;
|
||
15 years ago
|
|
||
|
// check if we can close all documents
|
||
|
for (it = m_views.begin(); it != m_views.end(); ++it)
|
||
|
{
|
||
|
// kdWarning()<<"searching for the part"<<endl;
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = *it;
|
||
15 years ago
|
if (!view->part()->queryClose())
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// and now close the documents
|
||
|
for (it = m_views.begin(); it != m_views.end(); ++it)
|
||
|
{
|
||
|
// now close all views
|
||
12 years ago
|
%{APPNAMELC}tdemdiView *view = *it;
|
||
15 years ago
|
|
||
|
m_manager->removePart( view->part() );
|
||
|
closeWindow( view );
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "%{APPNAMELC}tdemdi.moc"
|