📄 bookcase.cpp
字号:
/*************************************************************************** bookcase.cpp ------------------- begin : Wed Aug 29 21:00:54 CEST 2001 copyright : (C) 2001 by Robby Stephenson email : robby@periapsis.org ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of version 2 of the GNU General Public License as * * published by the Free Software Foundation; * * * ***************************************************************************/// application specific includes#include "bookcasedoc.h"#include "bcdetailedlistview.h"#include "bcunit.h"#include "bcunititem.h"#include "bookcase.h"#include "bcuniteditwidget.h"#include "bcgroupview.h"#include "configdialog.h"#include "bclabelaction.h"#include "xslthandler.h"#include "finddialog.h"#include "bcunititem.h"#include "bookcollection.h"#include <kiconloader.h>#include <kfiledialog.h>#include <kmenubar.h>#include <ktoolbar.h>#include <kprogress.h>#include <klocale.h>#include <kconfig.h>#include <kstdaction.h>#include <kaction.h>#include <kdebug.h>#include <kwin.h>#include <kprogress.h>#include <kstatusbar.h>#include <kprinter.h>#include <khtml_part.h>#include <khtmlview.h>#include <kglobal.h>#include <kstandarddirs.h>#include <kmessagebox.h>#include <kstringhandler.h>// include files for QT#include <qdir.h>#include <qsplitter.h>#include <qvbox.h>#include <qpaintdevicemetrics.h>#include <qpainter.h>#include <qtextedit.h>static const int ID_STATUS_MSG = 1;static const int ID_STATUS_COUNT = 2;//static const int PRINTED_PAGE_OVERLAP = 10;Bookcase::Bookcase(QWidget* parent_/*=0*/, const char* name_/*=0*/) : KMainWindow(parent_, name_), m_doc(0), m_config(kapp->config()), m_progress(0), m_configDlg(0), m_findDlg(0) { // do main window stuff like setting the icon initWindow(); // initialize the status bar and progress bar initStatusBar(); // set up all the actions initActions(); // create a document, which also creates an empty book collection // must be done before the different widgets are created initDocument(); // create the different widgets in the view initView(); initConnections(); readOptions(); m_fileSave->setEnabled(false); slotEnableOpenedActions(false); slotEnableModifiedActions(false); // not yet implemented m_editCut->setEnabled(false); m_editCopy->setEnabled(false); m_editPaste->setEnabled(false); slotUnitCount();}void Bookcase::initWindow() { setIcon(KGlobal::iconLoader()->loadIcon(QString::fromLatin1("bookcase"), KIcon::Desktop));}void Bookcase::initStatusBar() { statusBar()->insertItem(i18n("Ready."), ID_STATUS_MSG); statusBar()->setItemAlignment(ID_STATUS_MSG, Qt::AlignLeft | Qt::AlignVCenter); statusBar()->insertItem(QString(), ID_STATUS_COUNT, 0, true); statusBar()->setItemAlignment(ID_STATUS_COUNT, Qt::AlignLeft | Qt::AlignVCenter); m_progress = new KProgress(100, statusBar()); m_progress->setFixedHeight(statusBar()->minimumSizeHint().height()); statusBar()->addWidget(m_progress); m_progress->hide();}void Bookcase::initActions() {#if KDE_VERSION > 305 setStandardToolBarMenuEnabled(true);#endif m_fileNew = KStdAction::openNew(this, SLOT(slotFileNew()), actionCollection()); m_fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection()); m_fileOpenRecent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection()); m_fileSave = KStdAction::save(this, SLOT(slotFileSave()), actionCollection()); m_fileSaveAs = KStdAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection()); m_filePrint = KStdAction::print(this, SLOT(slotFilePrint()), actionCollection()); m_fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection()); m_editCut = KStdAction::cut(this, SLOT(slotEditCut()), actionCollection()); m_editCopy = KStdAction::copy(this, SLOT(slotEditCopy()), actionCollection()); m_editPaste = KStdAction::paste(this, SLOT(slotEditPaste()), actionCollection()); m_editFind = KStdAction::find(this, SLOT(slotEditFind()), actionCollection()); m_editFindNext = KStdAction::findNext(this, SLOT(slotEditFindNext()), actionCollection());#if KDE_VERSION < 306 m_toggleToolBar = KStdAction::showToolbar(this, SLOT(slotToggleToolBar()), actionCollection());#endif m_toggleStatusBar = KStdAction::showStatusbar(this, SLOT(slotToggleStatusBar()), actionCollection()); m_preferences = KStdAction::preferences(this, SLOT(slotShowConfigDialog()), actionCollection()); m_importBibtex = new KAction(i18n("Import Bibtex File..."), 0, this, SLOT(slotImportBibtex()), actionCollection(), "import_bibtex"); m_importBibtexml = new KAction(i18n("Import Bibtexml File..."), 0, this, SLOT(slotImportBibtexml()), actionCollection(), "import_bibtexml"); m_exportBibtex = new KAction(i18n("Export to Bibtex File..."), 0, this, SLOT(slotExportBibtex()), actionCollection(), "export_bibtex"); m_exportBibtexml = new KAction(i18n("Export to Bibtexml File..."), 0, this, SLOT(slotExportBibtexml()), actionCollection(), "export_bibtexml"); m_exportXSLT = new KAction(i18n("Export Using XSL Transform..."), 0, this, SLOT(slotExportXSLT()), actionCollection(), "export_xslt");// m_fileNewCollection = new KAction(i18n("New &Collection"), 0, this,// SLOT(slotFileNewCollection()),// actionCollection(),// "file_new_collection");#if KDE_VERSION < 306 m_toggleCollectionBar = new KToggleAction(i18n("Show Co&llection ToolBar"), 0, this, SLOT(slotToggleCollectionBar()), actionCollection(), "toggle_collection_bar");#endif (void) new BCLabelAction(i18n("Group by: "), 0, actionCollection(), "change_unit_grouping_label"); m_unitGrouping = new KSelectAction(i18n("Group Books By"), 0, this, SLOT(slotChangeGrouping()), actionCollection(), "change_unit_grouping"); m_fileNew->setToolTip(i18n("Create a new document")); m_fileOpen->setToolTip(i18n("Open an existing document")); m_fileOpenRecent->setToolTip(i18n("Open a recently used file")); m_fileSave->setToolTip(i18n("Save the actual document")); m_fileSaveAs->setToolTip(i18n("Save the actual document as...")); m_filePrint->setToolTip(i18n("Print the contents of the document...")); m_fileQuit->setToolTip(i18n("Quit the application")); m_editCut->setToolTip(i18n("Cut the selected section and puts it to the clipboard")); m_editCopy->setToolTip(i18n("Copy the selected section to the clipboard")); m_editPaste->setToolTip(i18n("Paste the clipboard contents to actual position")); m_editFind->setToolTip(i18n("Search in the document..."));#if KDE_VERSION < 306 m_toggleToolBar->setToolTip(i18n("Enable/disable the toolbar"));#endif m_toggleStatusBar->setToolTip(i18n("Enable/disable the statusbar")); m_preferences->setToolTip(i18n("Configure the options for the application...")); m_unitGrouping->setToolTip(i18n("Change the grouping of the collection"));#if KDE_VERSION < 306 m_toggleCollectionBar->setToolTip(i18n("Enable/disable the collection toolbar"));#endif m_importBibtexml->setToolTip(i18n("Import a Bibtexml file...")); m_exportBibtex->setToolTip(i18n("Export to Bibtex file...")); m_exportBibtexml->setToolTip(i18n("Export to Bibtexml file...")); m_exportXSLT->setToolTip(i18n("Export a file using an XSL transform..."));// createGUI(QString::fromLatin1("/home/robby/projects/bookcase/src/bookcaseui.rc")); createGUI(); // gets enabled once one search is done m_editFindNext->setEnabled(false);}void Bookcase::initDocument() { m_doc = new BookcaseDoc(this); // allow status messages from the document connect(m_doc, SIGNAL(signalStatusMsg(const QString&)), SLOT(slotStatusMsg(const QString&))); // do stuff that changes when the doc is modified connect(m_doc, SIGNAL(signalModified()), SLOT(slotEnableModifiedActions())); // overkill since a modified signal does not always mean a change in unit quantity connect(m_doc, SIGNAL(signalModified()), SLOT(slotUnitCount())); // update the progress bar connect(m_doc, SIGNAL(signalFractionDone(float)), SLOT(slotUpdateFractionDone(float))); // update the toolbar, unit count, and so on connect(m_doc, SIGNAL(signalCollectionAdded(BCCollection*)), SLOT(slotUpdateCollection(BCCollection*)));}void Bookcase::initView() { m_split = new QSplitter(this); setCentralWidget(m_split); // m_split is the parent widget for the left side column view m_groupView = new BCGroupView(m_split); // stack the detailed view and edit widget vertically QVBox* vbox = new QVBox(m_split); m_detailedView = new BCDetailedListView(m_doc, vbox); m_editWidget = new BCUnitEditWidget(vbox); // since the new doc is already initialized with one empty book collection BCCollection* coll = m_doc->collectionById(0); m_groupView->slotAddCollection(coll); m_detailedView->slotAddCollection(coll); m_editWidget->slotSetLayout(coll); // need to connect update signal BCCollectionListIterator it(m_doc->collectionList()); for( ; it.current(); ++it) { connect(it.current(), SIGNAL(signalGroupModified(BCCollection*, BCUnitGroup*)), m_groupView, SLOT(slotModifyGroup(BCCollection*, BCUnitGroup*))); } // this gets called in readOptions(), so not neccessary here //updateCollectionToolBar();}void Bookcase::initConnections() { // the two listviews signal when a unit is selected, pass it to the edit widget connect(m_groupView, SIGNAL(signalUnitSelected(BCUnit*)), m_editWidget, SLOT(slotSetContents(BCUnit*))); connect(m_detailedView, SIGNAL(signalUnitSelected(BCUnit*)), m_editWidget, SLOT(slotSetContents(BCUnit*))); // synchronize the selected signal between listviews// connect(m_groupView, SIGNAL(signalUnitSelected(BCUnit*)),// m_detailedView, SLOT(slotSetSelected(BCUnit*)));// connect(m_detailedView, SIGNAL(signalUnitSelected(BCUnit*)),// m_groupView, SLOT(slotSetSelected(BCUnit*))); // when one item is selected, clear the other connect(m_groupView, SIGNAL(signalUnitSelected(BCUnit*)), m_detailedView, SLOT(slotClearSelection())); connect(m_detailedView, SIGNAL(signalUnitSelected(BCUnit*)), m_groupView, SLOT(slotClearSelection())); connect(m_editWidget, SIGNAL(signalSaveUnit(BCUnit*)), m_doc, SLOT(slotSaveUnit(BCUnit*))); connect(m_groupView, SIGNAL(signalDeleteUnit(BCUnit*)), SLOT(slotDeleteUnit(BCUnit*))); connect(m_detailedView, SIGNAL(signalDeleteUnit(BCUnit*)), SLOT(slotDeleteUnit(BCUnit*))); connect(m_editWidget, SIGNAL(signalDeleteUnit(BCUnit*)), SLOT(slotDeleteUnit(BCUnit*))); connect(m_doc, SIGNAL(signalCollectionAdded(BCCollection*)), m_groupView, SLOT(slotAddCollection(BCCollection*))); connect(m_doc, SIGNAL(signalCollectionAdded(BCCollection*)), m_editWidget, SLOT(slotSetCollection(BCCollection*))); connect(m_doc, SIGNAL(signalCollectionAdded(BCCollection*)), m_detailedView, SLOT(slotAddCollection(BCCollection*))); connect(m_doc, SIGNAL(signalCollectionDeleted(BCCollection*)), this, SLOT(saveCollectionOptions(BCCollection*))); connect(m_doc, SIGNAL(signalCollectionDeleted(BCCollection*)), m_groupView, SLOT(slotRemoveItem(BCCollection*))); connect(m_doc, SIGNAL(signalCollectionDeleted(BCCollection*)), m_detailedView, SLOT(slotRemoveItem(BCCollection*))); // connect the added signal to both listviews// the group view receives BCCollection::signalGroupModified() so no add or modify action needed// connect(m_doc, SIGNAL(signalUnitAdded(BCUnit*)),// m_groupView, SLOT(slotAddItem(BCUnit*))); connect(m_doc, SIGNAL(signalUnitAdded(BCUnit*)), m_detailedView, SLOT(slotAddItem(BCUnit*))); connect(m_doc, SIGNAL(signalUnitAdded(BCUnit*)), m_editWidget, SLOT(slotUpdateCompletions(BCUnit*))); // connect the modified signal to both// connect(m_doc, SIGNAL(signalUnitModified(BCUnit*)),// m_groupView, SLOT(slotModifyItem(BCUnit*))); connect(m_doc, SIGNAL(signalUnitModified(BCUnit*)), m_detailedView, SLOT(slotModifyItem(BCUnit*))); connect(m_doc, SIGNAL(signalUnitModified(BCUnit*)), m_editWidget, SLOT(slotUpdateCompletions(BCUnit*))); // connect the deleted signal to both listviews// connect(m_doc, SIGNAL(signalUnitDeleted(BCUnit*)),// m_groupView, SLOT(slotRemoveItem(BCUnit*))); connect(m_doc, SIGNAL(signalUnitDeleted(BCUnit*)), m_detailedView, SLOT(slotRemoveItem(BCUnit*))); // if the doc wants a unit selected, show it in both detailed and group views connect(m_doc, SIGNAL(signalUnitSelected(BCUnit*)), m_detailedView, SLOT(slotSetSelected(BCUnit*))); connect(m_doc, SIGNAL(signalUnitSelected(BCUnit*)), m_groupView, SLOT(slotSetSelected(BCUnit*))); connect(m_doc, SIGNAL(signalUnitSelected(BCUnit*)), m_editWidget, SLOT(slotSetContents(BCUnit*))); connect(m_groupView, SIGNAL(signalRenameCollection(int, const QString&)), m_doc, SLOT(slotRenameCollection(int, const QString&)));}void Bookcase::slotInitFileOpen() { // check to see if most recent file should be opened m_config->setGroup("General Options"); if(m_config->readBoolEntry("Reopen Last File", false) && !m_config->readEntry("Last Open File").isEmpty()) { KURL lastFile = KURL(m_config->readEntry("Last Open File")); slotFileOpen(lastFile); }}// These are general options.// The options that can be changed in the "Configuration..." dialog// are taken care of by the ConfigDialog object.void Bookcase::saveOptions() {// kdDebug() << "Bookcase::saveOptions()" << endl; // for some reason, the m_config pointer is getting changed, but // I can't figure out where, so just to be on the safe side if(m_config != kapp->config()) { kdDebug() << "Bookcase::saveOptions() - inconsistent KConfig pointers!" << endl; m_config = kapp->config(); } m_config->setGroup("General Options"); m_config->writeEntry("Geometry", size()); m_config->writeEntry("Show Statusbar", m_toggleStatusBar->isChecked());#if KDE_VERSION < 306 toolBar("mainToolBar")->saveSettings(m_config, QString::fromLatin1("MainToolBar")); toolBar("collectionToolBar")->saveSettings(m_config, QString::fromLatin1("CollectionToolBar"));#endif m_fileOpenRecent->saveEntries(m_config, QString::fromLatin1("Recent Files")); if(m_doc->URL().fileName() != i18n("Untitled")) { m_config->writeEntry("Last Open File", m_doc->URL().url()); } m_config->writeEntry("Main Window Splitter Sizes", m_split->sizes()); BCCollectionListIterator it(m_doc->collectionList()); for( ; it.current(); ++it) { saveCollectionOptions(it.current()); }}void Bookcase::saveCollectionOptions(BCCollection* coll_) {// kdDebug() << "Bookcase::saveCollectionOptions()" << endl; if(!coll_) { return; } m_config->setGroup(QString::fromLatin1("Options - %1").arg(coll_->unitName())); QString groupName = coll_->unitGroups()[m_unitGrouping->currentItem()]; m_config->writeEntry("Group By", groupName); m_detailedView->saveLayout(m_config, QString::fromLatin1("Options - %1").arg(coll_->unitName())); m_config->writeEntry("ColumnNames", m_detailedView->columnNames());}void Bookcase::readOptions() {// kdDebug() << "Bookcase::readOptions()" << endl; // for some reason, the m_config pointer is getting changed, but // I can't figure out where, so just to be on the safe side if(m_config != kapp->config()) { kdDebug() << "Bookcase::readOptions() - inconsistent KConfig pointers!" << endl; m_config = kapp->config(); } m_config->setGroup("General Options");#if KDE_VERSION < 306 toolBar("mainToolBar")->applySettings(m_config, QString::fromLatin1("MainToolBar")); m_toggleToolBar->setChecked(!toolBar("mainToolBar")->isHidden()); slotToggleToolBar(); toolBar("collectionToolBar")->applySettings(m_config, QString::fromLatin1("CollectionToolBar")); m_toggleCollectionBar->setChecked(!toolBar("collectionToolBar")->isHidden()); slotToggleCollectionBar();#endif bool bViewStatusBar = m_config->readBoolEntry("Show Statusbar", true); m_toggleStatusBar->setChecked(bViewStatusBar); slotToggleStatusBar();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -