summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/tinykate.cpp
Unidiff
Diffstat (limited to 'noncore/apps/tinykate/tinykate.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/tinykate.cpp199
1 files changed, 199 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp
new file mode 100644
index 0000000..03c6e50
--- a/dev/null
+++ b/noncore/apps/tinykate/tinykate.cpp
@@ -0,0 +1,199 @@
1/***************************************************************************
2 tinykate.cpp
3 Tiny KATE mainwindow
4 -------------------
5 begin : November 2002
6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation. *
14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE *
15 * *
16 ***************************************************************************/
17#include <qwidget.h>
18#include <qaction.h>
19#include <qlayout.h>
20#include <qpe/qpetoolbar.h>
21#include <qpe/qpemenubar.h>
22#include <qpe/resource.h>
23#include <qpe/global.h>
24
25#include <opie/ofiledialog.h>
26
27#include "tinykate.h"
28#include "pics/file-new.xpm"
29#include "pics/file-open.xpm"
30#include "pics/file-save.xpm"
31#include "pics/edit-undo.xpm"
32#include "pics/edit-redo.xpm"
33
34#include <katedocument.h>
35#include <katehighlight.h>
36
37TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
38 QMainWindow( parent, name, f )
39{
40 currentView=0;
41 setCaption(tr("TinyKATE"));
42
43 setToolBarsMovable(FALSE);
44
45 QPEToolBar *bar = new QPEToolBar( this );
46 bar->setHorizontalStretchable( TRUE );
47 QPEMenuBar *mb = new QPEMenuBar( bar );
48 mb->setMargin( 0 );
49
50 tabwidget=new OTabWidget(this);
51 setCentralWidget(tabwidget);
52 connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *)));
53
54//FILE ACTIONS
55 QPopupMenu *popup = new QPopupMenu( this );
56
57 // Action for creating a new document
58 QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 );
59 a->addTo( popup );
60 connect(a, SIGNAL(activated()), this, SLOT(slotNew()));
61
62 // Action for opening an exisiting document
63 a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 );
64 a->addTo(popup);
65 connect(a, SIGNAL(activated()), this, SLOT(slotOpen()));
66
67
68 // Action for saving document
69 a = new QAction( tr( "Save" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 );
70 a->addTo(popup);
71
72 // Action for saving document to a new name
73 a = new QAction( tr( "Save As" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 );
74 a->addTo(popup);
75
76 // Action for closing the currently active document
77 a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 );
78 a->addTo(popup);
79 connect(a, SIGNAL(activated()), this, SLOT(slotClose()));
80
81
82 mb->insertItem(tr("File"),popup);
83
84//EDIT ACTIONS
85
86 // Action for cutting text
87 editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
88 editCut->addTo( bar );
89
90 // Action for Copying text
91 editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
92 editCopy->addTo( bar );
93
94 // Action for pasting text
95 editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
96 editPaste->addTo( bar );
97
98
99 // Action for finding / replacing text
100 editFindReplace = new QAction( tr( "Find/Replace" ), Resource::loadPixmap("find"), QString::null, 0, this, 0 );
101 editFindReplace->addTo( bar );
102
103 // Action for undo
104 editUndo = new QAction( tr( "Undo" ), QPixmap((const char**)edit_undo_xpm), QString::null, 0, this, 0 );
105 editUndo->addTo( bar );
106
107 // Action for redo
108 editRedo = new QAction( tr( "Redo" ), QPixmap((const char**)edit_redo_xpm), QString::null, 0, this, 0 );
109 editRedo->addTo( bar );
110
111//VIEW ACITONS
112 popup = new QPopupMenu( this );
113
114 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 );
115 viewIncFontSizes->addTo( popup );
116
117 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 );
118 viewDecFontSizes->addTo( popup );
119
120 mb->insertItem(tr("View"),popup);
121
122
123
124 popup = new QPopupMenu( this );
125 mb->insertItem(tr("Utils"),popup);
126
127//Highlight management
128 hlmenu=new QPopupMenu(this);
129 HlManager *hlm=HlManager::self();
130 for (int i=0;i<hlm->highlights();i++)
131 {
132 hlmenu->insertItem(hlm->hlName(i),i);
133 }
134 popup->insertItem(tr("Highlighting"),hlmenu);
135
136
137 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 );
138 utilSettings->addTo( popup);
139
140}
141
142
143void TinyKate::slotOpen( )
144{
145 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL);
146 if (!filename.isEmpty()) {
147 KateDocument *kd= new KateDocument(false, false, this,0,this);
148 KTextEditor::View *kv;
149 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"BLAH","BLAH");
150 qDebug(filename);
151 kd->open(filename);
152 }
153}
154
155void TinyKate::slotCurrentChanged( QWidget * view)
156{
157 if (currentView) {
158 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
159 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
160 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
161 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
162 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
163 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
164 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
165 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
166 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
167 }
168
169 currentView=(KTextEditor::View*)view;
170
171 connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
172 connect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
173 connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
174 connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
175 connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
176 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
177 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
178 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
179 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
180
181}
182
183void TinyKate::slotNew( )
184{
185 KateDocument *kd= new KateDocument(false, false, this,0,this);
186 KTextEditor::View *kv;
187 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),"BLAH",tr("Unnamed %1").arg(0));
188
189}
190
191void TinyKate::slotClose( )
192{
193 if (currentView==0) return;
194 KTextEditor::View *dv=currentView;
195 currentView=0;
196 tabwidget->removePage(dv);
197 delete dv->document();
198}
199