-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 92 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.h | 43 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 108 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 6 |
4 files changed, 118 insertions, 131 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp index 2e88067..92c15cb 100644 --- a/core/apps/textedit/fileBrowser.cpp +++ b/core/apps/textedit/fileBrowser.cpp @@ -14,16 +14,23 @@ #include "fileBrowser.h" #include <qpe/config.h> #include <qpe/resource.h> +#include <qpe/fileselector.h> #include <qpe/qpeapplication.h> +#include <qwidgetstack.h> #include <qlistview.h> +#include <qcombo.h> #include <qpushbutton.h> #include <qfile.h> #include <qmessagebox.h> #include <qlayout.h> #include <unistd.h> - +static int u_id = 1; +static int get_unique_id() +{ + return u_id++; +} fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) : QDialog( parent, name, modal, fl ) @@ -44,29 +51,23 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags dirLabel->setMaximumSize( QSize( 250, 15 ) ); layout->addWidget( dirLabel, 0, 0 ); - hideButton = new QPushButton( Resource::loadIconSet("s_hidden"),"",this,"hideButton"); - hideButton->setMinimumSize( QSize( 25, 25 ) ); - hideButton->setMaximumSize( QSize( 25, 25 ) ); - connect( hideButton,SIGNAL(toggled(bool)),this,SLOT( hideButtonPushed(bool)) ); - hideButton->setToggleButton(TRUE); - hideButton->setFlat(TRUE); - layout->addWidget( hideButton, 0, 1 ); - docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); docButton->setMinimumSize( QSize( 25, 25 ) ); docButton->setMaximumSize( QSize( 25, 25 ) ); connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); docButton->setFlat(TRUE); - layout->addWidget( docButton, 0, 2 ); + layout->addWidget( docButton, 0, 1 ); homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); homeButton->setMinimumSize( QSize( 25, 25 ) ); homeButton->setMaximumSize( QSize( 25, 25 ) ); connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); homeButton->setFlat(TRUE); - layout->addWidget( homeButton, 0, 3 ); + layout->addWidget( homeButton, 0, 2 ); + + FileStack = new QWidgetStack( this ); - ListView = new QListView( this, "ListView" ); + ListView = new QListView( this, "ListView" ); ListView->setMinimumSize( QSize( 100, 25 ) ); ListView->addColumn( tr( "Name" ) ); ListView->setColumnWidth(0,140); @@ -78,13 +79,25 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags ListView->setColumnAlignment(1,QListView::AlignRight); // ListView->setMultiSelection(true); // ListView->setSelectionMode(QListView::Extended); - ListView->setAllColumnsShowFocus( TRUE ); - layout->addMultiCellWidget( ListView, 1, 1, 0, 3 ); - - // signals and slots connections - connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); + FileStack->addWidget( ListView, get_unique_id() ); + + fileSelector = new FileSelector( "text/*", FileStack, "fileselector" , FALSE, FALSE); //buggy +// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); +// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); + connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); + layout->addMultiCellWidget( FileStack, 1, 1, 0, 2 ); + + SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); + SelectionCombo->setMinimumSize( QSize( 200, 25 ) ); + SelectionCombo->insertItem( tr( "Documents" ) ); + SelectionCombo->insertItem( tr( "All files" ) ); + SelectionCombo->insertItem( tr( "All files (incl. hidden)" ) ); + layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 2 ); + connect( SelectionCombo, SIGNAL( activated( const QString & ) ), + this, SLOT( selectionChanged( const QString & ) ) ); + currentDir.setPath(QDir::currentDirPath()); currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); @@ -96,6 +109,11 @@ fileBrowser::~fileBrowser() { } +void fileBrowser::setFileView( int selection ) +{ + SelectionCombo->setCurrentItem( selection ); + selectionChanged( SelectionCombo->currentText() ); +} void fileBrowser::populateList() { @@ -140,10 +158,6 @@ void fileBrowser::upDir() // qDebug(currentDir.canonicalPath()); } -void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) -{ -} - // you may want to switch these 2 functions. I like single clicks void fileBrowser::listClicked(QListViewItem *selectedItem) { @@ -216,15 +230,33 @@ void fileBrowser::docButtonPushed() { } -void fileBrowser::hideButtonPushed(bool b) { - if (b) - currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); +void fileBrowser::selectionChanged( const QString &select ) +{ + if ( select == "Documents") + { + FileStack->raiseWidget( fileSelector ); + dirLabel->hide(); + docButton->hide(); + homeButton->hide(); + } else - currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); - -// chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); -// currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); - populateList(); - update(); + { + if ( select == "All files" ) + currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); + else + currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); + populateList(); + update(); + dirLabel->show(); + docButton->show(); + homeButton->show(); + FileStack->raiseWidget( ListView ); + } +} + +void fileBrowser::docOpen( const DocLnk &doc ) +{ + fileList.append( doc.file().latin1() ); + accept(); } diff --git a/core/apps/textedit/fileBrowser.h b/core/apps/textedit/fileBrowser.h index 50ed485..d8f0d0d 100644 --- a/core/apps/textedit/fileBrowser.h +++ b/core/apps/textedit/fileBrowser.h @@ -17,21 +17,26 @@ copyright Sun 02-17-2002 22:28:23 L. J. Potter ljp@llornkcor.com //#include <qvariant.h> #include <qdialog.h> -#include <qfile.h> -#include <qdir.h> -#include <qstringlist.h> +#include <qfile.h> +#include <qdir.h> +#include <qstringlist.h> #include <qlabel.h> #include <qstring.h> -class QVBoxLayout; -class QHBoxLayout; -class QGridLayout; +#include <qpe/filemanager.h> + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; class QListView; class QListViewItem; class QPushButton; +class QComboBox; +class QWidgetStack; +class FileSelector; class fileBrowser : public QDialog -{ +{ Q_OBJECT public: @@ -39,6 +44,8 @@ public: fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); ~fileBrowser(); + void setFileView( int ); + QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton; QListView* ListView; @@ -48,18 +55,24 @@ public: QFile file; QStringList fileList; QListViewItem * item; + QComboBox *SelectionCombo; + QWidgetStack *FileStack; + FileSelector *fileSelector; + public slots: void homeButtonPushed(); - void docButtonPushed(); - void hideButtonPushed(bool); + void docButtonPushed(); + private: -private slots: - void upDir(); - void listDoubleClicked(QListViewItem *); - void listClicked(QListViewItem *); - void OnOK(); -protected slots: +private slots: + void upDir(); + void listClicked( QListViewItem * ); + void selectionChanged( const QString & ); + void OnOK(); + void docOpen( const DocLnk & ); + +protected slots: protected: diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 3a189cb..68ee1b4 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -49,6 +49,7 @@ #include <qtoolbutton.h> #include <qwidgetstack.h> #include <qcheckbox.h> +#include <qcombo.h> #include <unistd.h> #include <sys/stat.h> @@ -225,14 +226,6 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, #endif - - -static int u_id = 1; -static int get_unique_id() -{ - return u_id++; -} - static const int nfontsizes = 6; static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; @@ -265,17 +258,11 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); -// a->addTo( bar ); - a->addTo( file ); - - a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); a->addTo( bar ); a->addTo( file ); a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); -// a->addTo( bar ); file->insertSeparator(); a->addTo( file ); @@ -298,13 +285,12 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) a->addTo( editBar ); a->addTo( edit ); - a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); - edit->insertSeparator(); - a->addTo( bar ); - a->addTo( edit ); + a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); + edit->insertSeparator(); + a->addTo( bar ); + a->addTo( edit ); - int defsize; bool defb, defi, wrap; @@ -371,36 +357,26 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) this, SLOT( search() ) ); - a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); - a->addTo( searchBar ); - a->addTo( edit ); + a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); + a->addTo( searchBar ); + a->addTo( edit ); a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); a->addTo( searchBar ); - edit->insertSeparator(); - a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); - a->addTo( edit ); - - searchBar->hide(); - - editorStack = new QWidgetStack( this ); - setCentralWidget( editorStack ); + edit->insertSeparator(); + a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); + a->addTo( edit ); - searchVisible = FALSE; + searchBar->hide(); - fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy - connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); - connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); - connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); -// fileOpen(); - editor = new QpeEditor( editorStack ); + editor = new QpeEditor( this ); + setCentralWidget( editor ); editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); - editorStack->addWidget( editor, get_unique_id() ); connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); resize( 200, 300 ); @@ -429,7 +405,7 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) } else { fileOpen(); } - + viewSelection = cfg.readNumEntry( "FileView", 0 ); } TextEdit::~TextEdit() @@ -443,6 +419,7 @@ TextEdit::~TextEdit() cfg.writeEntry("Bold",f.bold()); cfg.writeEntry("Italic",f.italic()); cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); + cfg.writeEntry( "FileView", viewSelection ); } void TextEdit::zoomIn() @@ -513,33 +490,8 @@ void TextEdit::fileNew() void TextEdit::fileOpen() { -// if ( !save() ) { -// if ( QMessageBox::critical( this, tr( "Out of space" ), -// tr( "Text Editor was unable to\n" -// "save your changes.\n" -// "Free some space and try again.\n" -// "\nContinue anyway?" ), -// QMessageBox::Yes|QMessageBox::Escape, -// QMessageBox::No|QMessageBox::Default ) -// != QMessageBox::Yes ) -// return; -// else { -// delete doc; -// doc = 0; -// } -// } - menu->hide(); - editBar->hide(); - searchBar->hide(); - clearWState (WState_Reserved1 ); - editorStack->raiseWidget( fileSelector ); - fileSelector->reread(); - updateCaption(); -} - -void TextEdit::newFileOpen() -{ browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); + browseForFiles->setFileView( viewSelection ); browseForFiles->showMaximized(); if( browseForFiles->exec() != -1 ) { QString selFile= browseForFiles->selectedFileName; @@ -557,6 +509,7 @@ void TextEdit::newFileOpen() openFile(fileName ); } } + viewSelection = browseForFiles->SelectionCombo->currentItem(); } delete browseForFiles; editor->setEdited( FALSE); @@ -642,7 +595,6 @@ void TextEdit::newFile( const DocLnk &f ) DocLnk nf = f; nf.setType("text/plain"); clear(); - editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); editor->setFocus(); doc = new DocLnk(nf); @@ -652,6 +604,7 @@ void TextEdit::newFile( const DocLnk &f ) void TextEdit::openFile( const QString &f ) { + bFromDocView = TRUE; DocLnk nf; nf.setType("text/plain"); @@ -682,10 +635,10 @@ void TextEdit::openFile( const DocLnk &f ) if ( !fm.loadFile( f, txt ) ) { // ####### could be a new file qDebug( "Cannot open file" ); - + //return; } - + fileNew(); if ( doc ) delete doc; @@ -705,13 +658,11 @@ void TextEdit::showEditTools() // if ( !doc ) // close(); // clear(); - fileSelector->hide(); menu->show(); editBar->show(); if ( searchVisible ) searchBar->show(); // updateCaption(); - editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); } @@ -886,15 +837,8 @@ void TextEdit::setDocument(const QString& fileref) void TextEdit::closeEvent( QCloseEvent *e ) { - if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { - e->ignore(); - repaint(); -// fileRevert(); - - } else { - bFromDocView = FALSE; - e->accept(); - } + bFromDocView = FALSE; + e->accept(); } void TextEdit::accept() diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index e7e20e3..aca2933 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -58,7 +58,7 @@ public: void openFile( const QString & ); public slots: void editorChanged(); - + protected: void closeEvent( QCloseEvent *e ); @@ -68,7 +68,6 @@ private slots: void fileNew(); void fileRevert(); void fileOpen(); - void newFileOpen(); void changeStartConfig(bool); bool save(); bool saveAs(); @@ -103,8 +102,6 @@ private: void setFontSize(int sz, bool round_down_not_up); private: - QWidgetStack *editorStack; - FileSelector *fileSelector; fileSaver *fileSaveDlg; fileBrowser *browseForFiles; @@ -114,6 +111,7 @@ private: DocLnk *doc; bool searchVisible; bool bFromDocView; + int viewSelection; QAction *zin, *zout; QString currentFileName; }; |