[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/graphics/UNNAMED_READER/UNNAMED_READER
From: Stefan Kebekus <kebekus () kde ! org>
Date: 2006-12-11 4:15:44
Message-ID: 1165810544.540211.11643.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 612370 by kebekus:
improved Tabbed Interface, not finished yet
M +6 -18 CMakeLists.txt
A autoHideTabWidget.cpp [License: GPL (v2+) (wrong address)]
A autoHideTabWidget.h [License: GPL (v2+) (wrong address)]
D main-mdi.cpp
M +3 -3 main.cpp
D mainWindow-mdi.cpp
D mainWindow-mdi.h
M +89 -10 mainWindow.cpp
M +17 -4 mainWindow.h
--- trunk/playground/graphics/UNNAMED_READER/UNNAMED_READER/CMakeLists.txt \
#612369:612370 @@ -5,7 +5,11 @@
########### UNNAMED_READER ###############
-set(UNNAMED_READER_SRCS main.cpp mainWindow.cpp )
+set(UNNAMED_READER_SRCS
+ autoHideTabWidget.cpp
+ main.cpp
+ mainWindow.cpp
+ )
kde4_automoc(${UNNAMED_READER_SRCS})
@@ -16,25 +20,9 @@
install(TARGETS UNNAMED_READER DESTINATION ${BIN_INSTALL_DIR} )
-########### UNNAMED_READER-mdi ###############
-
-set(UNNAMED_READER_MDI_SRCS main-mdi.cpp mainWindow-mdi.cpp )
-
-kde4_automoc(${UNNAMED_READER_MDI_SRCS})
-
-kde4_add_executable(UNNAMED_READER_MDI ${UNNAMED_READER_MDI_SRCS})
-
-target_link_libraries(UNNAMED_READER_MDI UNNAMED_READERcore ${KDE4_KDECORE_LIBS} \
${KDE4_KPARTS_LIBS} )
-
-install(TARGETS UNNAMED_READER_MDI DESTINATION ${BIN_INSTALL_DIR} )
-
-
########### install files ###############
-#install( FILES UNNAMED_READER.desktop DESTINATION ${XDG_APPS_DIR} )
+install( FILES UNNAMED_READER.desktop DESTINATION ${XDG_APPS_DIR} )
#install( FILES UNNAMED_READER.kcfg DESTINATION ${KCFG_INSTALL_DIR} )
-#install( FILES UNNAMED_READERpart.rc DESTINATION \
${DATA_INSTALL_DIR}/UNNAMED_READERpart ) install( FILES UNNAMED_READERui.rc \
DESTINATION ${DATA_INSTALL_DIR}/UNNAMED_READER )
-#install( FILES UNNAMED_READERPluginGUI.desktop DESTINATION \
${SERVICETYPES_INSTALL_DIR} )
-#install( FILES UNNAMED_READERPluginGUIInterface.h DESTINATION \
${INCLUDE_INSTALL_DIR}) #install( FILES tips DESTINATION \
${DATA_INSTALL_DIR}/UNNAMED_READER )
--- trunk/playground/graphics/UNNAMED_READER/UNNAMED_READER/main.cpp #612369:612370
@@ -65,14 +65,14 @@
int main(int argc, char** argv)
{
KAboutData about ("UNNAMED_READER", I18N_NOOP("UNNAMED_READER"), "0.1",
- I18N_NOOP("UNNAMED_READER, the KDE document viewing programm"),
+ I18N_NOOP("UNNAMED_READER, the KDE document viewing program"),
KAboutData::License_GPL,
"(C) 2006, the UNNAMED_READER authors",
I18N_NOOP("Use this prgramm to display text documents. Most \
popular document formats are supported."), #warning UNNAMED_READER needs a homepage. \
Its address should be inserted here. 0);
about.addAuthor ("Stefan Kebekus",
- I18N_NOOP("Programm design, coding"),
+ I18N_NOOP("Program design, coding"),
"kebekus@kde.org");
KCmdLineArgs::init(argc, argv, &about);
@@ -91,7 +91,7 @@
if (args->isSet("unique")) {
// Check command line argument
if (args->count() != 1)
- KCmdLineArgs::usage(i18n("When the '--unique' option is specified, exactly \
one document must be specified.")); // This exists the programm + \
KCmdLineArgs::usage(i18n("When the '--unique' option is specified, exactly one \
document must be specified.")); // This exits the program
#warning TODO: add DBUS code here
} // End: "--unique" mode
--- trunk/playground/graphics/UNNAMED_READER/UNNAMED_READER/mainWindow.cpp \
#612369:612370 @@ -17,6 +17,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include "autoHideTabWidget.h"
#include "mainWindow.h"
#include "readerWidget.h"
#include "UNNAMED_READER_debug.h"
@@ -26,10 +27,11 @@
#include <klocale.h>
#include <kmainwindow.h>
#include <kmessagebox.h>
+#include <krecentfilesaction.h>
+#include <kstandarddirs.h>
#include <kstatusbar.h>
#include <kstdaction.h>
#include <QFile>
-#include <QTabWidget>
#include <QWorkspace>
namespace UNNAMED_READER {
@@ -39,20 +41,19 @@
mainWindow::mainWindow()
: KMainWindow( 0, "UNNAMED_READER main window" ),
- // workspace(new QWorkspace(this))
- workspace(new QTabWidget(this))
+ workspace(new autoHideTabWidget(this))
{
// tell the KMainWindow that this is indeed the main widget
setCentralWidget(workspace);
+ // setup a status bar
+ statusBar()->show();
+
// Setup our actions; this will also setup the GUI.
setupActions();
- // setup a status bar
- statusBar()->show();
+ readSettings();
- setupGUI();
-
// apply the saved mainwindow settings, if any, and ask the mainwindow
// to automatically save settings if changed: window size, toolbar
// position, icon size, etc.
@@ -62,14 +63,54 @@
mainWindow::~mainWindow()
{
+ kDebug(UNNAMED_READER_DEBUG, shell) << "mainWindow::~mainWindow()" << endl;
+
+ writeSettings();
}
+void mainWindow::readSettings()
+{
+ kDebug(UNNAMED_READER_DEBUG, shell) << "mainWindow::readSettings()" << endl;
+
+ action_openRecent->loadEntries( KGlobal::config() );
+ // Delete all entries that point to file which no longer exist. That
+ // saves us from a lot of useless entries in the "recent files.."
+ // menu.
+ QStringList items = action_openRecent->items();
+ for (int i = 0; i < items.size(); ++i) {
+ KUrl url(items.at(i));
+ if (!QFile::exists(url.path()))
+ action_openRecent->removeUrl(url);
+ }
+ // Enable the action, even if it is empty. Reason: if the action is
+ // in the toolbar, a single click can be used to open a file dislog
+ action_openRecent->setEnabled( true );
+}
+
+
+void mainWindow::writeSettings()
+{
+ kDebug(UNNAMED_READER_DEBUG, shell) << "mainWindow::writeSettings()" << endl;
+
+ action_openRecent->saveEntries( KGlobal::config() );
+ KGlobal::config()->sync();
+}
+
+
void mainWindow::setupActions()
{
KStdAction::open(this, SLOT(open()), actionCollection());
+
+ // Open recent files
+ action_openRecent = KStdAction::openRecent( this, SLOT(openUrl(KUrl)), \
actionCollection() ); + action_openRecent->setWhatsThis( i18n( \
"<qt><strong>Click</strong> to open a file or <strong>Click and hold</strong> to \
select a recent file" ) ); + action_openRecent->setToolTip( i18n( \
"<qt><strong>Click</strong> to open a file or <strong>Click and hold</strong> to \
select a recent file" ) ); +#warning TODO: use trigger slot of the action
+
KStdAction::quit(kapp, SLOT(quit()), actionCollection());
+
setupGUI();
}
@@ -86,10 +127,48 @@
return;
}
-#warning TODO: Check if this URL is already open. If yes, bring the label to the \
front + // Before opening a new tab, go through the list of documents that
+ // are already open, and check if the url points to one of these. If
+ // yes, bring that document to the front, and go to the reference
+ // part of the url, if there is one.
+ KUrl docurl(url);
+ docurl.setRef(QString::null);
+ QList<readerWidget *> readers = findChildren<readerWidget *>();
+ for(int i=0; i<readers.count(); i++) {
+ if (readers.at(i)->document() == docurl) {
+ workspace->setCurrentWidget(readers.at(i));
+ // Bring the window to the front, so the user sees where we're going.
+ activateWindow();
+ raise();
- readerWidget *label = new readerWidget(0);
- workspace->addTab(label, url.fileName());
+#warning TODO go to reference!
+
+ return;
+ }
+ }
+
+ readerWidget *label = new readerWidget(this, url);
+
+#warning TODO: set success to true or false, depending on whether the document could \
be opened or not. + bool success = true;
+
+ if (success) {
+ // Open a new tab that contains the readerWidget.
+#warning TODO: Check Qt documentation for the QTabWidget to check how to avoid \
flicker + workspace->addTab(label, url.fileName());
+ workspace->setCurrentWidget(label);
+
+ // Add the file to the list of recently used files if it is a
+ // local, but not a temporary file.
+ if (url.isLocalFile() && \
!url.path().startsWith(KStandardDirs::locateLocal("tmp", QString::null))) { + \
action_openRecent->addUrl(url); + writeSettings(); // Save the modified list, \
so other + // instances of the UNNAMED_READER have can
+ // use it immediately
+ }
+ } else { // If no success
+ delete workspace;
+ }
}
--- trunk/playground/graphics/UNNAMED_READER/UNNAMED_READER/mainWindow.h \
#612369:612370 @@ -28,8 +28,8 @@
#include <kmainwindow.h>
#include <kurl.h>
-class QTabWidget;
-class QWorkspace;
+class KRecentFilesAction;
+class autoHideTabWidget;
namespace UNNAMED_READER {
@@ -53,23 +53,36 @@
*/
virtual ~mainWindow();
+
+ public slots:
/**
* Opens a document
*/
void openUrl(KUrl url);
+
private slots:
/**
* Opens a document via a file dialog
*/
void open();
+
+ private:
+ // After all GUI items are constructed, this method is used in the
+ // constructor to read in the settings.
+ void readSettings();
- private:
+ // Save all settings; this method is called in the destructor
+ void writeSettings();
+
// This method is used in the constructor to generate the actions
// and the setup the GUI. It should not be called otherwise.
void setupActions();
- QTabWidget *workspace;
+ autoHideTabWidget *workspace;
+
+ // Action: open recent files
+ KRecentFilesAction *action_openRecent;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic