summaryrefslogtreecommitdiffstats
path: root/languages/cpp/app_templates/kscons_kxt/app.cpp
blob: dfd6024d1a24fb61c2aaa65f52eb2b2c135e6c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
%{CPP_TEMPLATE}

#include "%{APPNAMELC}.h"
#include "settings.h"
#include "prefs.h"

#include <tqdragobject.h>
#include <kprinter.h>
#include <tqpainter.h>
#include <tqpaintdevicemetrics.h>

#include <tdeconfigdialog.h>
#include <kglobal.h>
#include <klocale.h>
#include <kiconloader.h>
#include <tdeversion.h>
#include <kmenubar.h>
#include <kstatusbar.h>
#include <kkeydialog.h>
#include <ktip.h>

#include <kedittoolbar.h>

#include <tdestdaccel.h>
#include <tdeaction.h>
#include <kstdaction.h>

%{APPNAME}::%{APPNAME}()
    : TDEMainWindow( 0, "%{APPNAME}" ),
      m_view(new %{APPNAME}View(this)),
      m_printer(0)
{
    // accept dnd
    setAcceptDrops(true);

    // tell the TDEMainWindow that this is indeed the main widget
    setCentralWidget(m_view);

    // then, setup our actions
    setupActions();

    // and a status bar
    statusBar()->show();

    // 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();

    // allow the view to change the statusbar and caption
    connect(m_view, TQT_SIGNAL(signalChangeStatusbar(const TQString&)),
            this,   TQT_SLOT(changeStatusbar(const TQString&)));
    connect(m_view, TQT_SIGNAL(signalChangeCaption(const TQString&)),
            this,   TQT_SLOT(changeCaption(const TQString&)));

    showTipOnStart();
}

%{APPNAME}::~%{APPNAME}()
{
}

void %{APPNAME}::setupActions()
{
    KStdAction::openNew(this, TQT_SLOT(fileNew()), actionCollection());
    KStdAction::quit(kapp, TQT_SLOT(quit()), actionCollection());

    m_toolbarAction = KStdAction::showToolbar(this, TQT_SLOT(optionsShowToolbar()), actionCollection());
    m_statusbarAction = KStdAction::showStatusbar(this, TQT_SLOT(optionsShowStatusbar()), actionCollection());

    KStdAction::tipOfDay( this, TQT_SLOT( showTip() ), actionCollection()
            )->setWhatsThis(i18n("This shows useful tips on the use of this application."));

    KStdAction::keyBindings(this, TQT_SLOT(optionsConfigureKeys()), actionCollection());
    KStdAction::configureToolbars(this, TQT_SLOT(optionsConfigureToolbars()), actionCollection());
    KStdAction::preferences(this, TQT_SLOT(optionsPreferences()), actionCollection());

    // custom menu and menu item - the slot is in the class %{APPNAME}View
    TDEAction *custom = new TDEAction(i18n("Swi&tch Colors"), 0,
                                  m_view, TQT_SLOT(switchColors()),
                                  actionCollection(), "switch_action");

    createGUI();
}

void %{APPNAME}::fileNew()
{
    // this slot is called whenever the File->New menu is selected,
    // the New shortcut is pressed (usually CTRL+N) or the New toolbar
    // button is clicked

    // create a new window
    (new %{APPNAME})->show();
}

void %{APPNAME}::optionsShowToolbar()
{
    // this is all very cut and paste code for showing/hiding the
    // toolbar
    if (m_toolbarAction->isChecked())
        toolBar()->show();
    else
        toolBar()->hide();
}

void %{APPNAME}::optionsShowStatusbar()
{
    // show/hide the statusbar
    if (m_statusbarAction->isChecked())
        statusBar()->show();
    else
        statusBar()->hide();
}

void %{APPNAME}::optionsConfigureKeys()
{
    KKeyDialog::configure(actionCollection());
}

void %{APPNAME}::optionsConfigureToolbars()
{
    // use the standard toolbar editor
    saveMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
}

void %{APPNAME}::newToolbarConfig()
{
    // 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();

    applyMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
}

void %{APPNAME}::optionsPreferences()
{
	// 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
        TDEConfigDialog *dialog = new TDEConfigDialog(this, "settings", Settings::self(), KDialogBase::Swallow);
        dialog->addPage(new Prefs(), i18n("General"), "package_settings");
        connect(dialog, TQT_SIGNAL(settingsChanged()), m_view, TQT_SLOT(settingsChanged()));
        dialog->show();
}

void %{APPNAME}::changeStatusbar(const TQString& text)
{
    // display the text on the statusbar
    statusBar()->message(text, 2000);
}

void %{APPNAME}::changeCaption(const TQString& text)
{
    // display the text on the caption
    setCaption(text);
}

void %{APPNAME}::showTip()
{
    KTipDialog::showTip(this,TQString(),true);
}

void %{APPNAME}::showTipOnStart()
{
    KTipDialog::showTip(this);
}

void %{APPNAME}::switch_colors()
{
    if (!m_view)
        return;
    m_view->switchColors();
}

#include "%{APPNAMELC}.moc"