/*************************************************************************** mainwindow.cpp - description ------------------- begin : Sun Mar 26 2000 copyright : (C) 2000 by Alexander Theel email : alex.theel@gmx.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "mainwindow.h" //#define DEBUGGING #include #include #include #include "../icons/lo16-app-tuxcards.xpm" #include "../icons/lo32-app-tuxcards.xpm" #ifdef DEBUGGING #include "../icons/debug/showText.xpm" #include "../icons/debug/xml.xpm" #endif #include "../information/converter.h" #include "../information/CInformationCollection.h" #include "../persister.h" #include "../information/xmlpersister.h" #include "../information/htmlwriter.h" #include "../utilities/iniparser/configparser.h" #include #include #include #include #include #include #include #include "../utilities/strings.h" #include "./bookmark/BookmarkButton.h" #include "./dialogs/expiredElementsDialog/ExpiredElementsDialog.h" #include "../utilities/crypt/StringCrypter.h" #include "../version.h" #include "../global.h" #include "../Greetings.h" #include "../utilities/CIconManager.h" #define getIcon(x) CIconManager::getInstance().getIcon(x) // ------------------------------------------------------------------------------- MainWindow::MainWindow(QString arg) : mpCollection( NULLPTR ) , mpMenu( NULLPTR ) , mpOptionsDialog( NULLPTR ) , mConfiguration( CTuxCardsConfiguration::getInstance() ) , mpCactusBar( NULLPTR ) , mpSplit( NULLPTR ) , mpTree( NULLPTR ) , mpSingleEntryView( NULLPTR ) , mpEditor( NULLPTR ) , mpQuickLoader( NULLPTR ) , mpRecentFiles( NULLPTR ) , mpStatusBar( NULLPTR ) , mpLeftButton( NULLPTR ) , mpRightButton( NULLPTR ) , mpLockButton( NULLPTR ) , mpRemoveLockButton( NULLPTR ) , mHistory( ) , mPasswdDialog( ) // with parent as NULLPTR , mpMainTools( NULLPTR ) , mpEntryTools( NULLPTR ) , mpEditorTools( NULLPTR ) , miMainToolBarID( 0 ) , miEntryToolBarID( 0 ) , miEditorToolBarID( 0 ) // ------------------------------------------------------------------------------- { checkFirstTime(); // build up mainwindow setCaption("TuxCards"); setIcon(lo32_app_tuxcards_xpm); CIconManager::getInstance().setIconDirectory( mConfiguration.getStringValue( CTuxCardsConfiguration::S_ICON_DIR ) ); QHBox* layout=new QHBox(this); setCentralWidget(layout); settingUpCactusBar(layout); mpSplit = new QSplitter( layout ); checkPointer( mpSplit ); settingUpEditor( mpSplit ); settingUpTree( mpSplit ); mpSplit->moveToFirst( mpTree ); mpSplit->setOpaqueResize(TRUE); settingUpActions(); settingUpMenu(); settingUpToolBar(); settingUpStatusBar(); // settingUpQuickLoader(); // create optionsDialog mpOptionsDialog = new OptionsDialog( this, mConfiguration ); if ( NULLPTR != mpOptionsDialog ) { connect( mpOptionsDialog, SIGNAL(configurationChanged()), this, SLOT(applyConfiguration()) ); } // create little "showing-"dialog showDialog =new QDialog(this); QGroupBox* gb=new QGroupBox(1, Horizontal, showDialog); showLabel =new QLabel("Saving ...", gb); applyConfiguration(); TIMER_ID=startTimer(60000 * mConfiguration.getIntValue( CTuxCardsConfiguration::I_SAVE_ALL_MINUTES )); CHANGES=FALSE; // connect(mpTree, SIGNAL(freezeCHANGES()), this, SLOT(freezeCHANGES())); mHistory.setListener( this ); // build up tree, if config-file ('.tuxcards') was found bool result = FALSE; if ( arg != "" ) { result = open(arg); } else if ( mConfiguration.getStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME ) != "" ) { result = open(mConfiguration.getStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME )); } if ( !result ) { DELETE( mpCollection ); mpCollection = CInformationCollection::createDefaultCollection(); initializingCollection( "" ); if ( NULLPTR != mpCollection ) { mpCollection->setActiveElement( mpCollection->getRootElement() ); } } // show the completed window show(); showDonationMsg(); } // ------------------------------------------------------------------------------- MainWindow::~MainWindow() // ------------------------------------------------------------------------------- { DELETE( mpCollection ); } // ------------------------------------------------------------------------------- // This is an emergency exit. The application will be quited if not enough // memory is available to create all needed objects. // ------------------------------------------------------------------------------- void MainWindow::lowMemoryExit( void ) // ------------------------------------------------------------------------------- { std::cout<<"TuxCards ERROR\nNot enough memory to run application.\nTuxCards" " will be stopped!!!"<setEnabled( bHasPreviousElement ); if ( NULLPTR != mpRightButton ) mpRightButton->setEnabled( bHasNextElement ); } // ------------------------------------------------------------------------------- // Responses to the change of the active informationelement. Adds the new element // to the history. // ------------------------------------------------------------------------------- void MainWindow::activeInformationElementChanged( CInformationElement* pIE ) // ------------------------------------------------------------------------------- { if ( NULLPTR != pIE ) { mHistory.addElement( *pIE ); //mHistory.dump(); adjustEncryptionButtons(); } } // ------------------------------------------------------------------------------- // Enables and disables the "encryption-" and "remove encryption-" buttons. // The state of the buttons is set using the currently active information element. // ------------------------------------------------------------------------------- void MainWindow::adjustEncryptionButtons() // ------------------------------------------------------------------------------- { CInformationElement* pIE = getActiveIE(); if ( !pIE || !mpLockButton || !mpRemoveLockButton ) return; if ( pIE->isEncryptionEnabled() ) { bool bCurrentlyEncrypted = pIE->isCurrentlyEncrypted(); mpLockButton->setEnabled( !bCurrentlyEncrypted ); mpRemoveLockButton->setEnabled( !bCurrentlyEncrypted ); } else { mpLockButton->setEnabled( true ); mpRemoveLockButton->setEnabled( false ); } } // ------------------------------------------------------------------------------- void MainWindow::activatePreviousHistoryElement( void ) // ------------------------------------------------------------------------------- { if ( NULLPTR != mpCollection ) mpCollection->setActiveElement( mHistory.getPrevious() ); } // ------------------------------------------------------------------------------- void MainWindow::activateNextHistoryElement( void ) // ------------------------------------------------------------------------------- { if ( NULLPTR != mpCollection ) mpCollection->setActiveElement( mHistory.getNext() ); } // ------------------------------------------------------------------------------- void MainWindow::settingUpEditor( QWidget* pParent ) // ------------------------------------------------------------------------------- { mpSingleEntryView = new CSingleEntryView( pParent ); checkPointer( mpSingleEntryView ); if ( NULLPTR == mpSingleEntryView ) return; mpEditor = mpSingleEntryView->getEditor(); connect(mpEditor, SIGNAL(textChanged()), this, SLOT(recognizeChanges())); connect(mpEditor, SIGNAL(formatRecognized(InformationFormat)), this, SLOT(showRecognizedFormat(InformationFormat))); connect(mpEditor, SIGNAL(currentAlignmentChanged(int)), this, SLOT(textAlignmentChanged(int)) ); connect(mpSingleEntryView, SIGNAL(signalEntryDecrypted()), this, SLOT(adjustEncryptionButtons())); } // ------------------------------------------------------------------------------- void MainWindow::settingUpTree( QWidget* pParent ) // ------------------------------------------------------------------------------- { mpTree = new CTree( pParent, mConfiguration ); checkPointer( mpTree ); connect( mpTree, SIGNAL(showMessage(QString, int)), this, SLOT(showMessage(QString, int)) ); connect( mpTree, SIGNAL(makeVisible(SearchPosition*)), this, SLOT(makeVisible(SearchPosition*)) ); connect( mpTree, SIGNAL(addEntryToBookmarksSignal()), this, SLOT(addElementToBookmarksEvent()) ); } // ------------------------------------------------------------------------------- void MainWindow::settingUpCactusBar(QWidget* pParent) // ------------------------------------------------------------------------------- { // the cactusbar *must* be setup with some colors and text mpCactusBar = new CCactusBar(pParent, QColor(0,0,0),QColor(33,72,170), "Tux","Cards"); checkPointer( mpCactusBar ); } // ------------------------------------------------------------------------------- void MainWindow::settingUpStatusBar( void ) // ------------------------------------------------------------------------------- { mpStatusBar = new QStatusBar(this); checkPointer( mpStatusBar ); statusBar_ChangeLabel=new QLabel( " ", mpStatusBar ); statusBar_ChangeLabel->setFixedWidth(10); mpStatusBar->addWidget(statusBar_ChangeLabel, 0, TRUE); } // ------------------------------------------------------------------------------- void MainWindow::settingUpActions( void ) // ------------------------------------------------------------------------------- { editUndoAction = new QAction( "Undo", getIcon("undo"),"&Undo", CTRL+Key_Z, this); connect( mpEditor, SIGNAL(undoAvailable(bool)), editUndoAction, SLOT(setEnabled(bool)) ); connect( editUndoAction, SIGNAL(activated()), mpEditor, SLOT(undo()) ); editRedoAction = new QAction( "Redo", getIcon("redo"),"&Redo", CTRL+Key_Y, this); connect( mpEditor, SIGNAL(redoAvailable(bool)), editRedoAction, SLOT(setEnabled(bool)) ); connect( editRedoAction, SIGNAL(activated()), mpEditor, SLOT(redo()) ); editCopyAction = new QAction( "Copy", getIcon("editcopy"),"&Copy", CTRL+Key_C, this); connect( mpEditor, SIGNAL(copyAvailable(bool)), editCopyAction, SLOT(setEnabled(bool)) ); connect( editCopyAction, SIGNAL(activated()), mpEditor, SLOT(copy()) ); } // ------------------------------------------------------------------------------- void MainWindow::settingUpMenu( void ) // ------------------------------------------------------------------------------- { QPopupMenu *file = new QPopupMenu( this ); file->insertItem( getIcon("filenew" ), "&New", this, SLOT(clearAll()) ); file->insertItem( getIcon("fileopen"), "&Open File...", this, SLOT(open()) ); file->insertItem( getIcon("filesave"), "&Save", this, SLOT(save()), CTRL+Key_S ); file->insertItem( "Save &As...", this, SLOT(saveAs()) ); // file->insertItem( "Save Active Entry", this, SLOT(saveActiveEntry()) ); file->insertItem( getIcon("fileprint"), "&Print...", this, SLOT(print()) ); file->insertSeparator(); mpRecentFiles = new RecentFileList(this, file, mConfiguration.getStringValue( CTuxCardsConfiguration::S_RECENT_FILES )); checkPointer( mpRecentFiles ); connect( mpRecentFiles, SIGNAL(openFile(QString)), this, SLOT(slotSaveAndLoadNewFile(QString)) ); file->insertSeparator(); file->insertItem( "Export to &HTML...", this, SLOT(exportHTML()) ); file->insertSeparator(); file->insertItem( getIcon("exit"), "&Exit", this, SLOT(exit()) ); QPopupMenu* edit = new QPopupMenu( this ); editUndoAction->addTo( edit ); editRedoAction->addTo( edit ); edit->insertSeparator(); if ( NULLPTR != mpEditor ) { edit->insertItem( getIcon("editcut"), "Cu&t", mpEditor, SLOT(cut()), CTRL+Key_X ); editCopyAction->addTo( edit ); edit->insertItem( getIcon("editpaste"), "&Paste", mpEditor, SLOT(paste()), CTRL+Key_V ); edit->insertSeparator(); edit->insertItem( "Select &All", mpEditor, SLOT(selectAll()), CTRL+Key_A ); } QPopupMenu* toolbars = new QPopupMenu( this ); Q_CHECK_PTR( toolbars ); miMainToolBarID = toolbars->insertItem( "Show Main Toolbar", this, SLOT(toggleMainToolbarVisability()) ); miEntryToolBarID = toolbars->insertItem( "Show Entry Manipulation Toolbar", this, SLOT(toggleEntryToolbarVisability()) ); miEditorToolBarID = toolbars->insertItem( "Show Editor Toolbar", this, SLOT(toggleEditorToolbarVisability()) ); QPopupMenu* options = new QPopupMenu( this ); options->insertItem( "Toolbars", toolbars ); options->insertItem( "&Edit Options...", this, SLOT(editConfiguration()) ); QPopupMenu* extras = new QPopupMenu( this ); extras->insertItem( "Word Count", this, SLOT(wordCount()), CTRL+Key_W ); extras->insertItem( "Insert Current Date", this, SLOT(insertCurrentDate()), CTRL+Key_D ); extras->insertItem( "Insert Current Time", this, SLOT(insertCurrentTime()), CTRL+Key_T ); QPopupMenu *about = new QPopupMenu( this ); about->insertItem(QPixmap(lo16_app_tuxcards_xpm),"About TuxCards", this, SLOT(showAbout()) ); mpMenu = new QMenuBar(this); if ( NULLPTR != mpMenu ) { mpMenu->insertItem( "&File", file); mpMenu->insertItem( "&Edit", edit); mpMenu->insertItem( "&Options", options); mpMenu->insertItem( "E&xtras", extras); mpMenu->insertItem( "&About", about); } } // ------------------------------------------------------------------------------- void MainWindow::settingUpToolBar( void ) // ------------------------------------------------------------------------------- { mpMainTools = new QToolBar(this); QToolButton* clearTool = new QToolButton( getIcon("filenew"), "Clear whole Tree", 0, this, SLOT(clearAll()), mpMainTools); mpMainTools->addSeparator(); QToolButton* openTool = new QToolButton( getIcon("fileopen"), "Open a new File", 0, this, SLOT(open()), mpMainTools); QToolButton* saveTool=new QToolButton( getIcon("filesave"), "Save Data to File (Ctrl+S)", 0, this, SLOT(save()), mpMainTools); QToolButton* printTool=new QToolButton( getIcon("fileprint"), "Print current Entry", 0, this, SLOT(print()), mpMainTools); // ----------- add tools for editing the text within the editor -------------- mpMainTools->addSeparator(); editUndoAction->addTo( mpMainTools ); editRedoAction->addTo( mpMainTools ); QToolButton* editCutTool = new QToolButton( getIcon("editcut"), "Cut (Ctrl+X)", 0, mpEditor, SLOT(cut()), mpMainTools); editCopyAction->addTo( mpMainTools ); QToolButton* editPasteTool = new QToolButton( getIcon("editpaste"), "Paste (Ctrl+V)", 0, mpEditor, SLOT(paste()), mpMainTools); mpMainTools->addSeparator(); QToolButton* findTool = new QToolButton( getIcon("find"), "Search (Ctrl+F)", 0, this, SLOT(search()), mpMainTools); mpMainTools->addSeparator(); QWhatsThis::whatsThisButton(mpMainTools); QMimeSourceFactory::defaultFactory()->setPixmap("filenew", getIcon("filenew")); QWhatsThis::add(clearTool,"" "Clear whole Tree

" "Click this button to remove all entries from " "the tree."); QMimeSourceFactory::defaultFactory()->setPixmap("fileopen", getIcon("fileopen")); QWhatsThis::add(openTool, "Open a new File

" "Click this button to open a new data file. " "You can also select the Open command " "from the File menu."); QMimeSourceFactory::defaultFactory()->setPixmap("filesave", getIcon("filesave")); QWhatsThis::add(saveTool, "Save Data to File (Ctrl+S)

" "Click this button to save all data to disk. " "If this is a new file, you will be prompted " "for a file name."); QMimeSourceFactory::defaultFactory()->setPixmap("fileprint", getIcon("fileprint")); QWhatsThis::add(printTool, " Print current Entry

" "Click this button to print the currently active " "entry.

" "Please note: Only RTF-notes can be printed correctly. " "When printing an plain text note white spaces are " "ignored "); QMimeSourceFactory::defaultFactory()->setPixmap("undo", getIcon("undo")); editUndoAction->setWhatsThis("Undo (Ctrl+Z)

" "This button undoes changes made within the editor."); QMimeSourceFactory::defaultFactory()->setPixmap("redo", getIcon("redo")); editRedoAction->setWhatsThis("Redo (Ctrl+Y)

" "This button provides redo functionality for the editor."); QMimeSourceFactory::defaultFactory()->setPixmap("editcut", getIcon("editcut")); QWhatsThis::add(editCutTool, "Cut (Ctrl+X)

" "Cut text within the editor."); QMimeSourceFactory::defaultFactory()->setPixmap("editcopy", getIcon("editcopy")); editCopyAction->setWhatsThis("Copy (Ctrl+C)

" "Copy text within the editor."); QMimeSourceFactory::defaultFactory()->setPixmap("editpaste", getIcon("editpaste")); QWhatsThis::add(editPasteTool, "Paste (Ctrl+V)

" "Paste text within the editor."); QMimeSourceFactory::defaultFactory()->setPixmap("find", getIcon("find")); QWhatsThis::add(findTool, "Search (Ctrl+F)

" "Use this button, if you want to search for words " "within your data."); // ----------- add tools for moving elements within the tree -------------- mpEntryTools = new QToolBar(this); textFormatTool = new QToolButton( getIcon("filenew"), "Converts the Text Format", 0, this, SLOT(changeInformationFormat()), mpEntryTools); mpEntryTools->addSeparator(); QToolButton* addTreeElementTool = new QToolButton( getIcon("addTreeElement"), "Add Entry (INSERT)", 0, mpTree, SLOT(addElement()), mpEntryTools); QToolButton* changePropertyTool = new QToolButton( getIcon("changeProperty"), "Change Properties", 0, mpTree, SLOT(changeActiveElementProperties()), mpEntryTools); QToolButton* removeKnotenTool = new QToolButton( getIcon("delete"), "Remove active Entry (DELETE)", 0, mpTree, SLOT(askForDeletion()), mpEntryTools); mpLockButton = new QToolButton( getIcon("lock"), "Encrypt active Entry", 0, this, SLOT(encryptActiveEntry()), mpEntryTools ); mpRemoveLockButton = new QToolButton( getIcon("unlock"), "Remove Encryption from active Entry", 0, this, SLOT(removeEncryptionFromActiveEntry()), mpEntryTools ); mpEntryTools->addSeparator(); QToolButton* ieUpTool = new QToolButton( getIcon("upArrow"), "Move Current Entry Upwards", 0, this, SLOT(moveElementUp()), mpEntryTools); QToolButton* ieDownTool = new QToolButton( getIcon("downArrow"), "Move Current Entry Downwards", 0, this, SLOT(moveElementDown()), mpEntryTools); mpEntryTools->addSeparator(); mpLeftButton = new QToolButton( getIcon("back"), "Back, Previous Entry (Alt+Left)", 0, this, SLOT(activatePreviousHistoryElement()), mpEntryTools ); mpLeftButton->setEnabled(false); mpRightButton = new QToolButton( getIcon("forward"), "Forward, Next Entry (Alt+Right)", 0, this, SLOT(activateNextHistoryElement()), mpEntryTools ); mpRightButton->setEnabled(false); QWhatsThis::add(textFormatTool, "This button shows you the text format (ASCII / RTF) " "of the currently active entry. It does also let " "you convert between the two formats.

" "Usually, you do not need to worry about " "converting text formats."); QMimeSourceFactory::defaultFactory()->setPixmap("addTreeElement", getIcon("addTreeElement")); QWhatsThis::add(addTreeElementTool, "Add Entry (INSERT)

" "You can add further child-entries using this " "button. The same function is available through " "the context menu (right click on an item).

" "Clicking this button will open a dialog which " "prompts you for a name of the new entry."); QMimeSourceFactory::defaultFactory()->setPixmap("changeProp", getIcon("changeProperty")); QWhatsThis::add(changePropertyTool, "Change Property

" "Clicking this button, a dialog will appear. There, " "you may enter a new name and select another icon " "for the currently active entry.

" "You can also use the context menu (right click on " "an item) to call this function."); QMimeSourceFactory::defaultFactory()->setPixmap("delete", getIcon("delete")); QWhatsThis::add(removeKnotenTool, "Remove active Entry (DELETE)

" "This will remove the currently active entry and " "all child-entries from the tree.

" "You can also use the context menu (right click on " "an item) for this function."); QMimeSourceFactory::defaultFactory()->setPixmap("lock", getIcon("lock")); QWhatsThis::add(mpLockButton, "Encrypt active Entry

" "Encryptes the currently active entry.

" "If it was not encrypted yet a dialog for " "entering a password will open." ); QMimeSourceFactory::defaultFactory()->setPixmap("unlock", getIcon("unlock")); QWhatsThis::add(mpRemoveLockButton, "Remove Encryption

" "Removes encryption from active entry.

" "For security reasons, this action can only be " "done if the entry is decrypted." ); QMimeSourceFactory::defaultFactory()->setPixmap("upArrow", getIcon("upArrow")); QWhatsThis::add(ieUpTool, "Move Up

" "Moves the currently active entry one position upwards " "within the tree.

" "The entry is moved with all of its children."); QMimeSourceFactory::defaultFactory()->setPixmap("downArrow", getIcon("downArrow")); QWhatsThis::add(ieDownTool, " Move Down

" "Moves the currently active entry " "one position downwards within the tree.

" "The entry is moved with all of its children."); QMimeSourceFactory::defaultFactory()->setPixmap("historyBack", getIcon("back")); QWhatsThis::add(mpLeftButton, "History, Back (Alt+Left)

" "History function. If this button is clicked, then the " "last active entry is selected.

" "This is similar to the back button within your " "browser." ); QMimeSourceFactory::defaultFactory()->setPixmap("historyForward", getIcon("forward")); QWhatsThis::add(mpRightButton, "History, Forward (Alt+Right)

" "History function. If this button is clicked, then the " "next entry is selected.

" "This is similar to the forward button within your " "browser." ); // ----------- add tools for richtext to toolbar ------------------ //mpMainTools->addSeparator(); mpEditorTools = new QToolBar(this); pComboListStyle = new QComboBox( FALSE, mpEditorTools ); pComboListStyle->insertItem( tr("Standard") ); pComboListStyle->insertItem( tr("Bullet List (Disc)") ); pComboListStyle->insertItem( tr("Bullet List (Circle)") ); pComboListStyle->insertItem( tr("Bullet List (Square)") ); pComboListStyle->insertItem( tr("Ordered List (Decimal)") ); pComboListStyle->insertItem( tr("Ordered List (Alpha lower)") ); pComboListStyle->insertItem( tr("Ordered List (Alpha upper)") ); connect( pComboListStyle, SIGNAL( activated( int ) ), this, SLOT( textListStyle( int ) ) ); pComboFont = new QComboBox( TRUE, mpEditorTools ); QFontDatabase db; pComboFont->insertStringList( db.families() ); connect( pComboFont, SIGNAL( activated( const QString & ) ), this, SLOT( textFontFamily( const QString & ) ) ); pComboFont->lineEdit()->setText( QApplication::font().family() ); pComboSize = new QComboBox( TRUE, mpEditorTools ); QValueList sizes = db.standardSizes(); QValueList::Iterator it = sizes.begin(); for ( ; it != sizes.end(); ++it ) pComboSize->insertItem( QString::number( *it ) ); connect( pComboSize, SIGNAL( activated( const QString & ) ), this, SLOT( textFontSize( const QString & ) ) ); pComboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); textBoldTool = new QToolButton( getIcon("text_bold"), "Bold (Ctrl+B)", 0, this, SLOT(textBold()), mpEditorTools ); textBoldTool->setToggleButton(TRUE); textItalicTool = new QToolButton( getIcon("text_italic"), "Italic (Ctrl+I)", 0, this, SLOT(textItalic()), mpEditorTools ); textItalicTool->setToggleButton(TRUE); textUnderTool = new QToolButton( getIcon("text_under"), "Underline (Ctrl+U)", 0, this, SLOT(textUnder()), mpEditorTools); textUnderTool->setToggleButton(TRUE); QPixmap dummy(1,1); textColorTool = new QToolButton( dummy, "Color", 0, this, SLOT(textColor()), mpEditorTools ); textColorChanged(black); mpEditorTools->addSeparator(); textLeftTool = new QToolButton( getIcon("text_left"), "Align Left", 0, this, SLOT(textLeft()), mpEditorTools ); textLeftTool->setToggleButton(TRUE); textCenterTool = new QToolButton( getIcon("text_center"), "Center", 0, this, SLOT(textHCenter()), mpEditorTools ); textCenterTool->setToggleButton(TRUE); textRightTool = new QToolButton( getIcon("text_right"), "Align Right", 0, this, SLOT(textRight()), mpEditorTools ); textRightTool->setToggleButton(TRUE); textBlockTool = new QToolButton( getIcon("text_block"), "Text Block", 0, this, SLOT(textBlock()), mpEditorTools ); textBlockTool->setToggleButton(TRUE); QMimeSourceFactory::defaultFactory()->setPixmap("textBold", getIcon("text_bold")); QWhatsThis::add(textBoldTool, "Bold

" "Use this button, if you want to use bold text."); QMimeSourceFactory::defaultFactory()->setPixmap("textItalic", getIcon("text_italic")); QWhatsThis::add(textItalicTool, "Italic

" "Use this button, if you want to use italic text."); QMimeSourceFactory::defaultFactory()->setPixmap("textUnder", getIcon("text_under")); QWhatsThis::add(textUnderTool, "Underline

" "Use this button, if you want to use underlined text."); QMimeSourceFactory::defaultFactory()->setPixmap("textColor", getIcon("text_color")); QWhatsThis::add(textColorTool, "Text Color

" "Changes the color of the selected text."); QMimeSourceFactory::defaultFactory()->setPixmap("alignLeft", getIcon("text_left")); QWhatsThis::add(textLeftTool, "Align Left

" "Aligns the currently edited paragraph on the left side."); QMimeSourceFactory::defaultFactory()->setPixmap("alignCenter", getIcon("text_center")); QWhatsThis::add(textCenterTool, "Center

" "Centers the currently edited paragraph within the editor."); QMimeSourceFactory::defaultFactory()->setPixmap("alignRight", getIcon("text_left")); QWhatsThis::add(textRightTool, "Align Right

" "Aligns the currently edited paragraph on the right side."); QMimeSourceFactory::defaultFactory()->setPixmap("alignBlock", getIcon("text_block")); QWhatsThis::add(textBlockTool, "Text Block

" "Aligns the currently edited paragraph on both sides " "within the editor."); connect( mpEditor, SIGNAL( currentFontChanged(const QFont &) ), this, SLOT( textFontChanged(const QFont &) ) ); connect( mpEditor, SIGNAL( currentColorChanged(const QColor &) ), this, SLOT( textColorChanged(const QColor &) ) ); setMainToolbarVisible( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_SHOW_MAIN_TOOLBAR ) ); setEntryToolbarVisible( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_SHOW_ENTRY_TOOLBAR ) ); setEditorToolbarVisible( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_SHOW_EDITOR_TOOLBAR ) ); #ifdef DEBUGGING // --- add debug mpMainTools" std::cout<<"!!! still having debug turned on"<getActiveElement(); if ( NULLPTR == pElement ) return; BookmarkButton* b = new BookmarkButton( QPixmap( pElement->getIconFileName() ), pElement->getDescription(), mpQuickLoader, Path( pElement ) ); connect( b, SIGNAL(activatedSignal(Path*)), this, SLOT(quicklyLoad(Path*)) ); } /* // ------------------------------------------------------------------------------- void MainWindow::saveActiveEntry() // ------------------------------------------------------------------------------- { // saving eventual changes editor->writeCurrentTextToActiveInformationElement(); QString description=mpCollection->getActiveElement()->getDescription(); QString fileName=QDir::homeDirPath()+description+".xml"; XMLPersister::save(mpCollection, fileName); QPushButton* b= new QPushButton(QPixmap(mpCollection->getActiveElement()->getIconFileName()), description, mpQuickLoader); connect( b, SIGNAL(clicked(b->text())), this, SLOT(quicklyLoad(QString)) ); // mConfiguration.setStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME, fileName ); // mConfiguration.saveToFile(); showMessage("Entry saved and added to QuickLoader.", 5); }*/ // ------------------------------------------------------------------------------- void MainWindow::quicklyLoad(Path* path) // ------------------------------------------------------------------------------- { std::cout<<"load quickly "<toString()<getActiveElement(); if ( NULLPTR == pActiveElement ) { QMessageBox::information( 0, "Converter", "There is no active entry.", QMessageBox::Abort ); return; } if ( pActiveElement->getInformationFormat() == &InformationFormat::RTF) { QMessageBox::information( 0, "Converter", "Sorry, but converting RTF to ASCII " "is not implemented yet.", QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); return; } if (QMessageBox::Cancel == QMessageBox::warning(this, "Converting Information Format", "Are you sure to change the information " "format.\nSome of the text layout will be lost.", QMessageBox::Yes, QMessageBox::Cancel, QMessageBox::NoButton)) { return; } // converting mpEditor->writeCurrentTextToActiveInformationElement(); Converter::convert( *pActiveElement ); mpEditor->setTextFormat( Qt::RichText ); mpEditor->setText( pActiveElement->getInformation() ); mpCollection->setActiveElement( pActiveElement ); } // ------------------------------------------------------------------------------- void MainWindow::showRecognizedFormat(InformationFormat format) // ------------------------------------------------------------------------------- { textFormatTool->setPixmap(format.getPixmap()); // enabeling rtf-formatting stuff for rtf-information-items only bool b = format.equals(InformationFormat::RTF); textBoldTool->setEnabled(b); textItalicTool->setEnabled(b); textUnderTool->setEnabled(b); textColorTool->setEnabled(b); textLeftTool->setEnabled(b); textCenterTool->setEnabled(b); textRightTool->setEnabled(b); textBlockTool->setEnabled(b); } // ------------------------------------------------------------------------------- void MainWindow::textListStyle( int i ) // ------------------------------------------------------------------------------- { if ( !mpEditor ) return; if ( i == 0 ) mpEditor->setParagType( QStyleSheetItem::DisplayBlock, QStyleSheetItem::ListDisc ); else if ( i == 1 ) mpEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc ); else if ( i == 2 ) mpEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListCircle ); else if ( i == 3 ) mpEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListSquare ); else if ( i == 4 ) mpEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDecimal ); else if ( i == 5 ) mpEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListLowerAlpha ); else if ( i == 6 ) mpEditor->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListUpperAlpha ); mpEditor->viewport()->setFocus(); } // ------------------------------------------------------------------------------- void MainWindow::textFontFamily( const QString &f ) // ------------------------------------------------------------------------------- { if ( !mpEditor ) return; mpEditor->setFamily( f ); mpEditor->viewport()->setFocus(); } // ------------------------------------------------------------------------------- void MainWindow::textFontSize( const QString &p ) // ------------------------------------------------------------------------------- { if ( !mpEditor ) return; mpEditor->setPointSize( p.toInt() ); mpEditor->viewport()->setFocus(); } /** * whenever the font of the currently edited text within the editor * is changed -> the toolbuttons are adjusted */ // ------------------------------------------------------------------------------- void MainWindow::textFontChanged(const QFont &f) // ------------------------------------------------------------------------------- { pComboFont->lineEdit()->setText( f.family() ); pComboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); textBoldTool->setOn( f.bold() ); textItalicTool->setOn( f.italic() ); textUnderTool->setOn( f.underline() ); } // ------------------------------------------------------------------------------- void MainWindow::textColorChanged(const QColor &c) // ------------------------------------------------------------------------------- { QPixmap pix( getIcon("text_color") ); QPainter p; p.begin(&pix); p.fillRect(1,13, 16,4, QColor(c)); p.end(); textColorTool->setIconSet(pix); } // ------------------------------------------------------------------------------- void MainWindow::textAlignmentChanged(int a) // ------------------------------------------------------------------------------- { //std::cout<<"alignment changed to "<setOn(FALSE); textCenterTool->setOn(FALSE); textRightTool->setOn(FALSE); textBlockTool->setOn(FALSE); switch (a){ case Qt::AlignHCenter: textCenterTool->setOn(TRUE); //std::cout<<"center"<setOn(TRUE); //std::cout<<"right"<setOn(TRUE); //std::cout<<"just"<setOn(TRUE); //std::cout<<"left"<setBold(textBoldTool->isOn()); } // ------------------------------------------------------------------------------- void MainWindow::textItalic() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditor ) return; mpEditor->setItalic(textItalicTool->isOn()); } // ------------------------------------------------------------------------------- void MainWindow::textUnder() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditor ) return; mpEditor->setUnderline(textUnderTool->isOn()); } // ------------------------------------------------------------------------------- void MainWindow::textColor() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditor ) return; QColor c = QColorDialog::getColor(mpEditor->color(), this); if ( !c.isValid() ) return; mpEditor->setColor( c ); textColorChanged( c ); } // ------------------------------------------------------------------------------- void MainWindow::textLeft() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditor ) return; mpEditor->setAlignment(Qt::AlignLeft); } // ------------------------------------------------------------------------------- void MainWindow::textHCenter() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditor ) return; mpEditor->setAlignment(Qt::AlignHCenter); } // ------------------------------------------------------------------------------- void MainWindow::textRight() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditor ) return; mpEditor->setAlignment(Qt::AlignRight); } // ------------------------------------------------------------------------------- void MainWindow::textBlock() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditor ) return; mpEditor->setAlignment(Qt::AlignJustify); } /** * checks whether tuxcards runs for the first time with this version * if yes -> write new features in file */ // ------------------------------------------------------------------------------- void MainWindow::checkFirstTime() // ------------------------------------------------------------------------------- { QString configurationFileName = QDir::homeDirPath() + "/.tuxcards"; ConfigParser parser( configurationFileName, FALSE ); parser.setGroup("General"); QString version = parser.readEntry("Version", "previousVersion"); // TODO: Check whether this version is correct and does work if( version != "TuxCardsV1.0" ) { // write datafile QFile file( QDir::homeDirPath() + "/tuxcards_greeting" ); QTextStream* pLog = NULLPTR; if( !file.open(IO_WriteOnly) ) { std::cerr<<"TuxCards - cannot write to "<setEncoding(QTextStream::UnicodeUTF8); } *pLog<message(s, seconds*1000); } /** * to keep track of changes, put a marker in the statusbar, * and update the global variable 'CHANGES' to prevent unnecessary savings */ // ------------------------------------------------------------------------------- void MainWindow::recognizeChanges() // ------------------------------------------------------------------------------- { CHANGES=TRUE; statusBar_ChangeLabel->setText("*"); } /** * sets the text within the editor 'mpEditor' to 'text' */ /*void MainWindow::updateText(QString text){ mpEditor->setText(text); } */ // responde to menu-calls ---------------------------------------------- // ------------------------------------------------------------------------------- void MainWindow::clearAll() // ------------------------------------------------------------------------------- { if (askForSaving("Do you want to save before deleting all items " "and creating a new file?") == QMessageBox::Cancel) return; DELETE( mpCollection ); mpCollection = CInformationCollection::createDefaultCollection(); initializingCollection(""); } // ------------------------------------------------------------------------------- int MainWindow::askForSaving(QString question) // ------------------------------------------------------------------------------- { int result = QMessageBox::No; if ( CHANGES ){ result = QMessageBox::warning( this, "Saving", question, QMessageBox::Yes,QMessageBox::No,QMessageBox::Cancel ); if (result==QMessageBox::Yes) save(); } return result; } /** * Before calling this method the informationCollection 'mpCollection' * must be valid !!! */ // ------------------------------------------------------------------------------- void MainWindow::initializingCollection( QString collectionName ) // ------------------------------------------------------------------------------- { if ( (NULLPTR == mpCollection) || (NULLPTR == mpSingleEntryView) ) return; //std::cout<<"vorher"<createTreeFromCollection( *mpCollection ); connect( mpCollection, SIGNAL(activeInformationElementChanged(CInformationElement*)), mpSingleEntryView, SLOT(activeInformationElementChanged(CInformationElement*)) ); connect( mpCollection, SIGNAL(activeInformationElementChanged(CInformationElement*)), this, SLOT(activeInformationElementChanged(CInformationElement*)) ); connect( mpCollection, SIGNAL(modelHasChanged()), this, SLOT(recognizeChanges()) ); if ( NULLPTR != mpEditor ) mpEditor->clear(); // collection successfully created and system set up with it // !!! if using a windows-system: this might not work since '/' not in path int i=collectionName.findRev('/'); if (i>-1) mpTree->setColumnText(collectionName.mid(i+1)); else mpTree->setColumnText(collectionName); CHANGES=FALSE; statusBar_ChangeLabel->setText(" "); selectLastActiveElement(); mpCollection->addView( &mHistory ); mpCollection->addView( mpTree ); mpCollection->addView( mpSingleEntryView ); mConfiguration.setStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME, collectionName ); mConfiguration.saveToFile(); // because the dataFileName has changed } // ------------------------------------------------------------------------------- CInformationElement* MainWindow::getActiveIE() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpCollection ) return NULLPTR; return mpCollection->getActiveElement(); } /** * adapter for 'open(QString h)' */ // ------------------------------------------------------------------------------- void MainWindow::open() // ------------------------------------------------------------------------------- { // give a chance to save the file before opening another one if (askForSaving("Do you want to save before opening another data file?") == QMessageBox::Cancel) return; // getting dataFileName QString fileName( QFileDialog::getOpenFileName() ); if ( fileName.isNull() || fileName=="" ) showMessage("No Filename specified.", 5); else open(fileName); } /** * Returns TRUE, if file was opend successfully; otherwise FALSE. */ // ------------------------------------------------------------------------------- bool MainWindow::open( QString fileName ) // ------------------------------------------------------------------------------- { bool retVal = FALSE; int format = getDataFileFormat(fileName); if ( format == 2 ) retVal = openXMLDataFile(fileName); else if ( format == 1 ) retVal = openOldDataFile(fileName); else { QMessageBox::critical( this, "Opening a data file", "Could not open file '"+fileName+"'
or did not " "recognize the dataformat.", "Ok"); } if (retVal) { if ( NULLPTR != mpRecentFiles ) { mpRecentFiles->setOnTop(fileName); } } return retVal; } /** * Opens a file and detects the fileformat. * i.e. '2' == XML-File (the new TuxCards format) * '1' == Old-File (the old TuxCards format, that was used since version 0.5) * '0' == unknown format */ // ------------------------------------------------------------------------------- int MainWindow::getDataFileFormat(QString fileName) // ------------------------------------------------------------------------------- { QFile file(fileName); if ( !file.open(IO_ReadOnly) ) { //showMessage("ERROR could not open '"+fileName+"' for reading.", 5); return 0; } QTextStream t( &file ); QString line=t.readLine(); //cout<<"readLine="<setActiveElement( path ); } else { //std::cout<<"Path is invalid"<setActiveElement( mpCollection->getRootElement() ); } mpTree->verticalScrollBar()->setValue( mConfiguration.getIntValue( CTuxCardsConfiguration::I_TREE_VSCROLLBAR_VALUE ) ); } // ------------------------------------------------------------------------------- void MainWindow::save() // ------------------------------------------------------------------------------- { if (mConfiguration.getStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME ) == "") { saveAs(); } else { save(mConfiguration.getStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME )); } } // ------------------------------------------------------------------------------- void MainWindow::saveAs() // ------------------------------------------------------------------------------- { QString newFileName( QFileDialog::getSaveFileName() ); if ( newFileName.isNull() || newFileName=="" ) { showMessage("No Filename specified.", 5); return; } save(newFileName); if ( NULLPTR != mpRecentFiles ) { mpRecentFiles->setOnTop(newFileName); } mConfiguration.setStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME, newFileName ); mConfiguration.saveToFile(); } // ------------------------------------------------------------------------------- void MainWindow::save(QString fileName) // ------------------------------------------------------------------------------- { if ( (NULLPTR == mpCollection) || (NULLPTR == mpEditor) ) return; if ( (QDir::homeDirPath() + TUX_CONFIG_FILE) == fileName ) { QMessageBox::warning( this, "Saving", "File not saved.\n" "Please do not use \"" + fileName +"\"" " as file name.", QMessageBox::Abort, NULL ); return; } if ( !CHANGES ) { showMessage("No changes.", 5); return; } // before saving -> move current file i.e. "myfile.data" to "myfile.data~" if ( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_CREATE_BACKUP_FILE ) ) { QDir tmp; QString sFileName = mConfiguration.getStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME ); tmp.rename( sFileName, sFileName + "~" ); } // saving eventual changes mpEditor->writeCurrentTextToActiveInformationElement(); XMLPersister::save( *mpCollection, fileName ); int i=fileName.findRev('/'); if (i>-1) mpTree->setColumnText(fileName.mid(i+1)); else mpTree->setColumnText(fileName); mConfiguration.setStringValue( CTuxCardsConfiguration::S_DATA_FILE_NAME, fileName ); mConfiguration.saveToFile(); statusBar_ChangeLabel->setText(" "); CHANGES=FALSE; showMessage("Saved to '" + fileName + "'.", 5); callingExecutionStatement(); } // ------------------------------------------------------------------------------- void MainWindow::callingExecutionStatement() // ------------------------------------------------------------------------------- { system( mConfiguration.getStringValue( CTuxCardsConfiguration::S_EXECUTE_STATEMENT ).ascii() ); } /** * opens the current file from disk and exports it to */ // ------------------------------------------------------------------------------- void MainWindow::exportHTML() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpCollection ) return; QString dirPath = QFileDialog::getExistingDirectory( QDir::homeDirPath(), this, "get existing directory", "Choose a directory", TRUE ); if ( dirPath.isEmpty() ) return; bool bSuccess = HTMLWriter::writeCollectionToHTMLFile( *mpCollection, dirPath ); // done if ( FALSE != bSuccess ) { QMessageBox::information( this, "HTML-Export", "HTMLExport " "(" + QString(TUX_SHORT_VERSION) + ")" " finished, successfully.\n\n" "The data are stored in\n"+dirPath, 1); } else { QMessageBox::warning( this, "HTML-Export", "HTMLExport " "(" + QString(TUX_SHORT_VERSION) + ")" " not successfully.\n\n" "Please check write permission and disk space\n" "(" + dirPath + ")", "Abort"); } } // ------------------------------------------------------------------------------- void MainWindow::keyPressEvent(QKeyEvent* k) // ------------------------------------------------------------------------------- { if ( !k || !mpTree || !mpSingleEntryView ) return; switch( k->state() ) { case ControlButton: //cout<<"CTL + "<ascii()<<"\ttext="<text()<<"\tkey="<key()<key() == Key_S) save(); else if ( (ControlButton == k->state()) && (Qt::Key_F == k->key()) ) search(); break; case AltButton: if ( k->key() == Key_Left ) activatePreviousHistoryElement(); else if ( k->key() == Key_Right ) activateNextHistoryElement(); break; default: if ( Qt::Key_F5 == k->key() ) { if ( mpEditor->hasFocus() ) mpTree->setFocus(); else mpEditor->setFocus(); } else k->ignore(); break; } } // ------------------------------------------------------------------------------- void MainWindow::exit() // ------------------------------------------------------------------------------- { close(); // calls 'closeEvent(..)' indirectly } // ------------------------------------------------------------------------------- void MainWindow::wordCount( void ) // ------------------------------------------------------------------------------- { if ( (NULLPTR == mpCollection) || (NULLPTR == mpEditor) ) return; mpEditor->writeCurrentTextToActiveInformationElement(); CInformationElement* pActiveElement = mpCollection->getActiveElement(); if ( NULLPTR == pActiveElement ) { QMessageBox::information( 0, "WordCount", "There is no active entry.", QMessageBox::Abort ); return; } QString text = pActiveElement->getInformationText(); //std::cout<lines(); int parags = mpEditor->paragraphs(); QMessageBox::information( this, "TuxCards", "

Current Entry contains
" +QString::number(words) +(words > 1 ? " words
" : "word
") +QString::number(lines) + (lines > 1 ? " lines
" : " line
" ) +QString::number(parags) + (parags > 1 ? " paragraphs" : "paragraph" ) +".
"); } // ------------------------------------------------------------------------------- void MainWindow::insertCurrentDate( void ) // ------------------------------------------------------------------------------- { if ( NULLPTR != mpEditor ) mpEditor->insert( QDate::currentDate().toString() ); } // ------------------------------------------------------------------------------- void MainWindow::insertCurrentTime() // ------------------------------------------------------------------------------- { if ( NULLPTR != mpEditor ) mpEditor->insert( QTime::currentTime().toString() ); } // ------------------------------------------------------------------------------- void MainWindow::showAbout() // ------------------------------------------------------------------------------- { QMessageBox::about( this, "TuxCards", "TuxCards - The Notebook for TuxFreaks\n" +QString(TUX_VERSION)+"\n\n" "www.tuxcards.de\n\n" "Copyright (C) 2000-2004 Alexander Theel\n" "alex.theel@gmx.net" ); } /** * saves the data automatically by closing/quitting the program */ // ------------------------------------------------------------------------------- void MainWindow::closeEvent(QCloseEvent *e) // ------------------------------------------------------------------------------- { // accept signal e->accept(); // default implementation of this method // we always save the options; the splitter-size may have changed if ( NULLPTR != mpCollection ) { Path path( mpCollection->getActiveElement() ); mConfiguration.setStringValue( CTuxCardsConfiguration::S_LAST_ACTIVE_ELEM_PATH, path.toString() ); } mConfiguration.setIntValue( CTuxCardsConfiguration::I_TREE_VSCROLLBAR_VALUE, mpTree->verticalScrollBar()->value()); mConfiguration.setIntValue( CTuxCardsConfiguration::I_WINDOW_WIDTH, width() ); mConfiguration.setIntValue( CTuxCardsConfiguration::I_WINDOW_HEIGHT, height() ); mConfiguration.setIntValue( CTuxCardsConfiguration::I_TREE_WIDTH, mpSplit->sizes().first() ); mConfiguration.setIntValue( CTuxCardsConfiguration::I_EDITOR_WIDTH, mpSplit->sizes().last() ); if ( NULLPTR != mpRecentFiles ) { mConfiguration.setStringValue( CTuxCardsConfiguration::S_RECENT_FILES, mpRecentFiles->toString() ); } mConfiguration.saveToFile(); if (!CHANGES) return; if ( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_SAVE_WHEN_LEAVING ) || (QMessageBox::warning( this, "Save before exiting.", "Do you want to save before leaving TuxCards?", "Yes", "No") == 0) ) { showDialog->show(); save(); showDialog->hide(); } } // ------------------------------------------------------------------------------- void MainWindow::toggleMainToolbarVisability() // ------------------------------------------------------------------------------- { bool bValue = mConfiguration.getBoolValue( CTuxCardsConfiguration::B_SHOW_MAIN_TOOLBAR ); bValue = !bValue; setMainToolbarVisible( bValue ); mConfiguration.saveToFile(); } // ------------------------------------------------------------------------------- void MainWindow::setMainToolbarVisible( bool bVisible ) // ------------------------------------------------------------------------------- { mConfiguration.setBoolValue( CTuxCardsConfiguration::B_SHOW_MAIN_TOOLBAR, bVisible ); if ( mpMainTools ) { if (bVisible) mpMainTools->show(); else mpMainTools->hide(); } if ( mpMenu ) mpMenu->setItemChecked( miMainToolBarID, bVisible ); } // ------------------------------------------------------------------------------- void MainWindow::toggleEntryToolbarVisability() // ------------------------------------------------------------------------------- { bool bValue = mConfiguration.getBoolValue( CTuxCardsConfiguration::B_SHOW_ENTRY_TOOLBAR ); bValue = !bValue; setEntryToolbarVisible( bValue ); mConfiguration.saveToFile(); } // ------------------------------------------------------------------------------- void MainWindow::setEntryToolbarVisible( bool bVisible ) // ------------------------------------------------------------------------------- { mConfiguration.setBoolValue( CTuxCardsConfiguration::B_SHOW_ENTRY_TOOLBAR, bVisible ); if ( mpEntryTools ) { if (bVisible) mpEntryTools->show(); else mpEntryTools->hide(); } if ( mpMenu ) mpMenu->setItemChecked( miEntryToolBarID, bVisible ); } // ------------------------------------------------------------------------------- void MainWindow::toggleEditorToolbarVisability() // ------------------------------------------------------------------------------- { bool bValue = mConfiguration.getBoolValue( CTuxCardsConfiguration::B_SHOW_EDITOR_TOOLBAR ); bValue = !bValue; setEditorToolbarVisible( bValue ); mConfiguration.saveToFile(); } // ------------------------------------------------------------------------------- void MainWindow::setEditorToolbarVisible( bool bVisible ) // ------------------------------------------------------------------------------- { mConfiguration.setBoolValue( CTuxCardsConfiguration::B_SHOW_EDITOR_TOOLBAR, bVisible ); if ( mpEditorTools ) { if (bVisible) mpEditorTools->show(); else mpEditorTools->hide(); } if ( mpMenu ) mpMenu->setItemChecked( miEditorToolBarID, bVisible ); } // ------------------------------------------------------------------------------- void MainWindow::editConfiguration( void ) // ------------------------------------------------------------------------------- { if ( NULLPTR == mpOptionsDialog ) return; mpOptionsDialog->setUp(); } // ------------------------------------------------------------------------------- void MainWindow::applyConfiguration() // ------------------------------------------------------------------------------- { // cactusbar if ( NULLPTR != mpCactusBar ) { mpCactusBar->toggleCactus( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_IS_CACTUSBAR_ENABLED ) ); QString t1,t2; if( mConfiguration.getBoolValue(CTuxCardsConfiguration::B_IS_HTEXT_ENABLED) ) { t1=mConfiguration.getStringValue( CTuxCardsConfiguration::S_TEXT_ONE ); t2=mConfiguration.getStringValue( CTuxCardsConfiguration::S_TEXT_TWO ); } else { t1 = ""; t2 = ""; } mpCactusBar->change( mConfiguration.getTopColor(), mConfiguration.getBottomColor(), t1, t2, mConfiguration.getFontColor() ); if( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_IS_VTEXT_ENABLED ) ) { t1 = mConfiguration.getStringValue( CTuxCardsConfiguration::S_VERTICAL_TEXT ); } else { t1 = ""; } mpCactusBar->setVerticalText( t1, mConfiguration.getBoolValue( CTuxCardsConfiguration::B_ALIGN_VTEXT ) ); mpCactusBar->setFlowerDirectory( mConfiguration.getStringValue( CTuxCardsConfiguration::S_FLOWER_DIR ) ); mpCactusBar->paint(); } // autosave killTimer(TIMER_ID); if ( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_AUTOSAVE ) ) TIMER_ID=startTimer( 60000 * mConfiguration.getIntValue( CTuxCardsConfiguration::I_SAVE_ALL_MINUTES ) ); // editor if ( NULLPTR != mpEditor ) { QFont font = mConfiguration.getASCIIEditorFont().toFont(); mpEditor->setFont(font); mpEditor->setTabStopWidth( mConfiguration.getIntValue( CTuxCardsConfiguration::I_TAB_SIZE ) * QFontMetrics(font).width('X') ); mpEditor->setWordWrap( mConfiguration.getIntValue( CTuxCardsConfiguration::I_WORD_WRAP ) ); if ( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_LINEBREAK_MODERN )) mpEditor->setLinebreakMode( LINEBREAK_MODERN ); else mpEditor->setLinebreakMode( LINEBREAK_CLASSIC ); } // tree mpTree->setFont( mConfiguration.getTreeFont().toFont() ); // windowsize & splitter setWindowGeometry( mConfiguration.getIntValue( CTuxCardsConfiguration::I_WINDOW_WIDTH ), mConfiguration.getIntValue( CTuxCardsConfiguration::I_WINDOW_HEIGHT ), mConfiguration.getIntValue( CTuxCardsConfiguration::I_TREE_WIDTH ), mConfiguration.getIntValue( CTuxCardsConfiguration::I_EDITOR_WIDTH ) ); } // ------------------------------------------------------------------------------- void MainWindow::setWindowGeometry( int windowWidth, int windowHeight, int treeSize, int editorSize ) // ------------------------------------------------------------------------------- { resize(windowWidth, windowHeight); lst = new QValueList(); lst->append(treeSize); lst->append(editorSize); mpSplit->setSizes( *lst ); } // ------------------------------------------------------------------------------- void MainWindow::search() // ------------------------------------------------------------------------------- { if ( (NULLPTR == mpEditor) || (NULLPTR == mpTree) ) return; mpEditor->writeCurrentTextToActiveInformationElement(); mpTree->search(); } // ------------------------------------------------------------------------------- void MainWindow::print() // ------------------------------------------------------------------------------- { if ( (NULLPTR == mpCollection) || (NULLPTR == mpCollection->getActiveElement()) ) return; if ( mpCollection->getActiveElement()->getInformationFormat() == &InformationFormat::ASCII ) { QMessageBox::information( this, "Printing", "I suggest to convert this note to " "rtf before printing.", "Ok" ); } if ( NULLPTR == mpEditor ) return; mpEditor->writeCurrentTextToActiveInformationElement(); #ifndef QT_NO_PRINTER QPrinter printer; printer.setFullPage(TRUE); if ( printer.setup( this ) ) { QPainter p( &printer ); // Check that there is a valid device to print to. if ( !p.device() ) return; QPaintDeviceMetrics metrics( p.device() ); int dpix = metrics.logicalDpiX(); int dpiy = metrics.logicalDpiY(); const int margin = 72; // pt QRect body( margin * dpix / 72, margin * dpiy / 72, metrics.width() - margin * dpix / 72 * 2, metrics.height() - margin * dpiy / 72 * 2 ); QFont font( mConfiguration.getASCIIEditorFont().toFont() ); font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing QSimpleRichText richText( mpCollection->getActiveElement()->getInformation(), font, mpEditor->context(), mpEditor->styleSheet(), mpEditor->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; do{ richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.setFont( font ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() >= body.top() + richText.height() ) break; printer.newPage(); page++; }while (TRUE); } #endif } // ------------------------------------------------------------------------------- void MainWindow::makeVisible( SearchPosition* pPosition ) // ------------------------------------------------------------------------------- { if ( (NULLPTR == mpCollection) || (NULLPTR == pPosition) || (NULLPTR == mpEditor) ) return; mpCollection->setActiveElement( *(pPosition->getPath()) ); int paragraph = pPosition->getLine(); int pos = pPosition->getPos(); int len = pPosition->getLen(); this->setActiveWindow(); mpEditor->setSelection(paragraph,pos, paragraph,pos+len, 0); mpEditor->setFocus(); mpEditor->setCursorPosition(paragraph, pos+len); mpEditor->ensureCursorVisible(); } // ------------------------------------------------------------------------------- void MainWindow::moveElementUp() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpCollection ) return; if ( NULLPTR == mpCollection->getActiveElement() ) return; ((CTreeInformationElement*) mpCollection->getActiveElement())->moveOneUp(); } // ------------------------------------------------------------------------------- void MainWindow::moveElementDown() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpCollection ) return; if ( NULLPTR == mpCollection->getActiveElement() ) return; ((CTreeInformationElement*) mpCollection->getActiveElement())->moveOneDown(); } // ------------------------------------------------------------------------------- void MainWindow::encryptActiveEntry() // ------------------------------------------------------------------------------- { if ( (NULLPTR == mpCollection) ) return; CInformationElement* pActiveElement = mpCollection->getActiveElement(); if ( NULLPTR == pActiveElement ) { QMessageBox::information( 0, "TuxCards", "There is no active entry.", QMessageBox::Abort ); return; } if ( !mConfiguration.askForUsingEncryption() ) { return; } if ( !pActiveElement->isEncryptionEnabled() ) { // Passwd needed mPasswdDialog.setUp( pActiveElement->getDescription() ); //std::cout<enableEncryption( true, mPasswdDialog.getPasswd() ); } } if ( !pActiveElement->isCurrentlyEncrypted() ) { pActiveElement->encrypt(); mpSingleEntryView->activeInformationElementChanged( pActiveElement ); adjustEncryptionButtons(); } } // ------------------------------------------------------------------------------- void MainWindow::removeEncryptionFromActiveEntry() // ------------------------------------------------------------------------------- { if ( (NULLPTR == mpCollection) ) return; CInformationElement* pActiveElement = mpCollection->getActiveElement(); if ( NULLPTR == pActiveElement ) { QMessageBox::information( 0, "TuxCards", "There is no active entry.", QMessageBox::Abort ); return; } if ( pActiveElement->isCurrentlyEncrypted() ) { QMessageBox::information( 0, "TuxCards", "Entry must be decrypted " "before encription can be removed.", QMessageBox::Abort ); return; } pActiveElement->enableEncryption( false, "" ); adjustEncryptionButtons(); } // ------------------------------------------------------------------------------- void MainWindow::showDonationMsg() // ------------------------------------------------------------------------------- { if ( mConfiguration.getBoolValue( CTuxCardsConfiguration::B_SHOW_DONATION_MSG_1_2 ) ) { return; } QMessageBox::about( this, "TuxCards", "

TuxCards 1.2 is published as Donationware

" "" "

You may use it freely and without charge as stated within the GPL.

" "" "

Do you like TuxCards ... " "and you want to enable the development of new " "features? Or do you want to ensure a high quality of future releases " "or simply compensate for ftp-server costs? Then you are welcome to " "donate EUR 5 to the author. (At your wish US$ 5 or an equivalent amount " "in your currency.)

" "" "

Please, use www.tuxcards.de/donations.html for a secure donation via internet.

" "" "

Or simply send a letter with your amount to

" "" "Alexander Theel
" "Am Trommlerbusch 24 d
" "02708 Loebau
" "Germany
" ); mConfiguration.setBoolValue( CTuxCardsConfiguration::B_SHOW_DONATION_MSG_1_2, true ); mConfiguration.saveToFile(); } /*********************** debug methods **********************************/ // ------------------------------------------------------------------------------- void MainWindow::debugShowRTFTextSource() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditor ) return; QTextEdit* outputWindow=new QTextEdit(); outputWindow->resize(400,400); outputWindow->setTextFormat(Qt::PlainText); outputWindow->setText(mpEditor->getText()); outputWindow->show(); } // ------------------------------------------------------------------------------- void MainWindow::debugShowXMLCode() // ------------------------------------------------------------------------------- { if ( NULLPTR == mpCollection ) return; QTextEdit* outputWindow=new QTextEdit(); outputWindow->resize(400,400); outputWindow->setTextFormat(Qt::PlainText); outputWindow->setText(mpCollection->toXML()); outputWindow->show(); }