Aktuelle Zeit: Di 16. Apr 2024, 18:38



Neues Thema erstellenAntwort schreiben Seite 1 von 4   [ 39 Beiträge ]
Gehe zu Seite 1, 2, 3, 4  Nächste
Autor Nachricht
 Betreff des Beitrags: Texteditor QT( c++ )
BeitragVerfasst: Mo 2. Apr 2012, 17:51 
Administrator
Benutzeravatar

Registriert: Mi 8. Jun 2011, 15:57
Beiträge: 723
Wohnort: 127.0.0.1
Ich hab mir mal auf die schnelle einen Texteditor in C++ gemacht
Kann folgendes :
I/O mit FileDialog
HTML in einer WebView anzeigen hab ich von nexi :D
Text Zoom
Auto Save

Bin noch nicht ganz fertig .... eine Syntax Highlight ist auch geplant ....

main.cpp
Spoiler :
Code:
#include "mainwindowimpl.h"
// ------------------
// V0.1 2012 QT 4.6.2
// ------------------
unsigned char nSettings_0 = 0x00;
/*
 * 1 -> Text changed
 *
 * 2 -> Web View
 *
 * // Save the Auto save intervall for the Auto save State Machine
 * 3 -> State Machine -> Auto save Bit 1
 * 4 -> State Machine -> Auto save Bit 2
 * 5 -> State Machine -> Auto save Bit 3
 *
 * 6 -> /
 * 7 -> /
 * 8 -> /
 */
unsigned char nAutoSave = 0;
QString StrSave = "";

// start
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) : QMainWindow(parent, f)
{setupUi(this);SHOW_MainEdit MainEdit->setTextFormat(Qt::PlainText);MainEdit->setText(TEXT_EXAMPLE);}
//closeevent
void MainWindowImpl::closeEvent(QCloseEvent *event){
   if(nSettings_0&1){
   QMessageBox msgBox;
   msgBox.setText("Save ?");
   msgBox.setIcon(QMessageBox::Information);
   msgBox.setInformativeText("Do you want to save the file ?");
   msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
   msgBox.setDefaultButton(QMessageBox::Ok);
   int ret = msgBox.exec();
    switch (ret) {
         case QMessageBox::Save:SAVE_Main_Edit if(nSettings_0&1){event->ignore();}break;
         case QMessageBox::Discard:event->accept();break;
         case QMessageBox::Cancel:event->ignore();break;
         default:event->ignore();break;
       }   
   }else{event->accept();}
}
//open
void MainWindowImpl::on_action_ffnen_activated(){
QString filename = QFileDialog::getOpenFileName(
        this, tr("Open Document"),
        QDir::currentPath(),tr("Document files All files (*)") );
    if(!filename.isNull()){
       StrSave = filename.toAscii();
       QFile file(filename.toAscii());
      file.open(QIODevice::ReadOnly | QIODevice::Text);
      MainEdit->setText(file.readAll());
      file.close();
     }
}
//save
void MainWindowImpl::on_actionSpeichern_activated(){
bool B_Save = 0;unsigned char nAbort=0;
do{
     if(StrSave == ""){
       QString filename = QFileDialog::getSaveFileName( this, tr("Save Document"),QDir::currentPath(), tr("Document files All files (*)") );
       if(filename.toAscii() != "")StrSave = filename.toAscii();else nAbort=10;
       }else{B_Save = 1;}
       if(B_Save == 0){
         QMessageBox msgBox;
         msgBox.setText("Save failed !");
         msgBox.setIcon(QMessageBox::Information);
         msgBox.setInformativeText("Do you want to retry save the file ?");
         msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
         msgBox.setDefaultButton(QMessageBox::Ok);
         int ret = msgBox.exec();
          if(ret==QMessageBox::Cancel) {nSettings_0 &= 254;/*11111110*/nAbort=10;}    
      }
      nAbort++;B_Save = 1;
  }while(!Save(StrSave,MainEdit->text())||nAbort<=9);
}
// save as227
void MainWindowImpl::on_actionSpeichern_unter_activated()
{StrSave == "";SAVE_Main_Edit }
//text changed
void MainWindowImpl::on_MainEdit_textChanged(){
   if(MainEdit->text() != "")nSettings_0 |= 1;
   nAutoSave++;
      if(AutoSave((nSettings_0&28),nAutoSave))
         {SAVE_Main_Edit nAutoSave=0;}

}
// toggle HTML view
void MainWindowImpl::on_actionHML_Anzeigen_activated(int ){
   if(nSettings_0&2){nSettings_0&=253;/*11111101*/SHOW_MainEdit
   }else{nSettings_0|=2;SHOW_MainView
   MainView->setHtml(QLatin1String(MainEdit->text()));
   QTest::qSleep(20);WEB_RELOAD
   MainWindowImpl::on_actionStop_activated();
   }
}
//web control
void MainWindowImpl::on_actionReload_activated(){WEB_RELOAD}
void MainWindowImpl::on_actionStop_activated(){WEB_STOP}
void MainWindowImpl::on_actionGoogle_activated(){WEB_GO_HOME}
//zoom
void MainWindowImpl::on_actionZoom_in_activated(int ){MainEdit->zoomIn(1);}
void MainWindowImpl::on_actionZoom_out_activated(int ){MainEdit->zoomOut(1);}
// Auto Save selection
void MainWindowImpl::on_actionAll_5_changes_2_activated(){RESET_AutoSave nSettings_0 |= 4;}
void MainWindowImpl::on_actionAll_5_changes_activated(){RESET_AutoSave nSettings_0 |= 8;}
void MainWindowImpl::on_actionAll_10_changes_activated(){RESET_AutoSave nSettings_0 |= 16;}
void MainWindowImpl::on_actionAll_20_changes_activated(){RESET_AutoSave nSettings_0 |= 20;}
void MainWindowImpl::on_actionAll_40_changes_activated(){RESET_AutoSave nSettings_0 |= 24;}
void MainWindowImpl::on_actionAll_50_changes_activated(){RESET_AutoSave nSettings_0 |= 28;}
void MainWindowImpl::on_actionAuto_Backup_off_activated(){RESET_AutoSave}


main.h
Spoiler :
Code:
#include <QMainWindow>
#include <QApplication>
#include <QFileDialog>
#include <QTextBrowser>
#include <QFile>
#include <QString>
#include <QTextStream>
#include <QMessageBox>
#include <QCloseEvent>
#include <QWebView>
#include <QTest>
#include "ui_mainwindow.h"
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
#define TEXT_EXAMPLE ((1)?(!("")):("<html>\n<head>\n<title>Beschreibung der Seite</title>\n</head>\n<body>\n<h1>Hello World !</h1>\n</body>\n</html>"))
#define WEB_HOME_LINK      "https://www.google.com"
#define WEB_RELOAD      if(nSettings_0&0x02){MainView->reload();}
#define WEB_STOP      if(nSettings_0&0x02){MainView->stop();}
#define WEB_GO_HOME      if(nSettings_0&0x02){MainView->load(QUrl(WEB_HOME_LINK));}
#define SHOW_MainView    MainEdit->setVisible(0);MainView->setVisible(1);
#define SHOW_MainEdit    MainEdit->setVisible(1);MainView->setVisible(0);
#define RESET_AutoSave   nSettings_0&=227;nAutoSave=0;/*11100011*/
#define SAVE_Main_Edit  MainWindowImpl::on_actionSpeichern_activated();
//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
   MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
private slots:
   void on_actionAuto_Backup_off_activated();
   void on_actionAll_5_changes_2_activated();
   void on_actionAll_40_changes_activated();
   void on_actionAll_5_changes_activated();
   void on_actionAll_10_changes_activated();
   void on_actionAll_20_changes_activated();
   void on_actionAll_50_changes_activated();
   void on_actionZoom_in_activated(int );
   void on_actionZoom_out_activated(int );
   void on_actionReload_activated();
   void on_actionStop_activated();
   void on_actionGoogle_activated();
   void on_actionHML_Anzeigen_activated(int );
   void on_actionSpeichern_unter_activated();
   void on_actionSpeichern_activated();
   void on_action_ffnen_activated();
   void on_MainEdit_textChanged();
   void closeEvent(QCloseEvent *event);

//save funktion
bool Save(QString StrFilename,QString StrToSave)
{
    QFile file(StrFilename.toAscii());
    if( file.exists() ){
       file.open(QIODevice::WriteOnly | QIODevice::Text);
       QTextStream out(&file);
       out << StrToSave;
       file.close();
       return(1);
         }
   return(0);
}
bool AutoSave(unsigned char nSettings_0,unsigned char nAutoSave)
{
          if(nSettings_0== 4 && nAutoSave>=2)//00000100
      {return(1);}
      else if(nSettings_0== 8 && nAutoSave>=4)//00001000
      {return(1);}
      else if(nSettings_0==12 && nAutoSave>=8)//00001100
      {return(1);}
      else if(nSettings_0==16 && nAutoSave>=10)//00010000
      {return(1);}
      else if(nSettings_0==20 && nAutoSave>=20)//00010100
      {return(1);}
      else if(nSettings_0==24 && nAutoSave>=30)//00011000
      {return(1);}
      else if(nSettings_0==28 && nAutoSave>=40)//00011100
      {return(1);}
      return(0);
}


};
#endif





Projekt Download :

_________________
nexusfail und Miss Rabiit sind die besten :D


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
Verfasst: Mo 2. Apr 2012, 17:51 


Nach oben
  
 
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Mo 2. Apr 2012, 23:46 
Benutzeravatar

Registriert: Do 8. Mär 2012, 20:35
Beiträge: 66
Cr0w +1

_________________
Free software for a free world ,GNU/Linux. Cr0w √ (-1) ♥ u :)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Di 3. Apr 2012, 20:39 
Benutzeravatar

Registriert: Do 8. Mär 2012, 20:35
Beiträge: 66
Probier es mal mit :

Code:
QTextEdit *editor = new QTextEdit;
srchiliteqt::Qt4SyntaxHighlighter *highlighter =
 new srchiliteqt::Qt4SyntaxHighlighter(editor->document());
highlighter->init("java.lang");

_________________
Free software for a free world ,GNU/Linux. Cr0w √ (-1) ♥ u :)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Di 3. Apr 2012, 20:51 
Administrator
Benutzeravatar

Registriert: Mi 8. Jun 2011, 15:57
Beiträge: 723
Wohnort: 127.0.0.1
Ja aber die gehen nicht !

_________________
nexusfail und Miss Rabiit sind die besten :D


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Mi 4. Apr 2012, 07:08 
Benutzeravatar

Registriert: Fr 8. Jul 2011, 13:30
Beiträge: 347
Wohnort: https://www.accountkiller.com/removal-requested
<textarea name = 'Texteditor' cols = '500' rows = '250'>

_________________
https://www.accountkiller.com/removal-requested

Бороться и победить в борьбе против мониторинга!
Kjempe og vinne kamp mot overvåkning!
Pugnare et pugna vincere versus circumdare custodiere!


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Mi 4. Apr 2012, 08:48 
Administrator
Benutzeravatar

Registriert: Mi 8. Jun 2011, 15:57
Beiträge: 723
Wohnort: 127.0.0.1
Karv hat geschrieben:
<textarea name = 'Texteditor' cols = '500' rows = '250'>


WAS ?
Ich glaube du verwechselst da was , das eine ist C++ das andere ist HTML ,
zur Lösung der Problem brauche ich eine Syntax Highlight Funktion ....
oder willst du wissen ob der Befehl geht ? ... Ja tut er !

_________________
nexusfail und Miss Rabiit sind die besten :D


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Mi 4. Apr 2012, 10:10 
Benutzeravatar

Registriert: Do 8. Mär 2012, 20:35
Beiträge: 66
Karv hat geschrieben:
<textarea name = 'Texteditor' cols = '500' rows = '250'>


Vielleicht meint er dass man es auch in HTML lösen kann oder dass man die Funktion einer Seite nutzen kann ?!

_________________
Free software for a free world ,GNU/Linux. Cr0w √ (-1) ♥ u :)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Mi 4. Apr 2012, 10:12 
Benutzeravatar

Registriert: Do 8. Mär 2012, 20:35
Beiträge: 66
Miss Rabbit hat geschrieben:
Vielleicht meint er dass man es auch in HTML lösen kann oder dass man die Funktion einer Seite nutzen kann ?!


aber ich mach doch keinen Editor für HTML in HTML ! und offline soll es auch funktionieren !

_________________
Free software for a free world ,GNU/Linux. Cr0w √ (-1) ♥ u :)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Mi 4. Apr 2012, 10:33 
Benutzeravatar

Registriert: Fr 8. Jul 2011, 13:30
Beiträge: 347
Wohnort: https://www.accountkiller.com/removal-requested
Das ist ein Textfeld... da kann man was reinschreiben... ergo n "editor" oder n "vi" - speichern is natürlich ne andere Sache - das war übrigens trolling... -.-

_________________
https://www.accountkiller.com/removal-requested

Бороться и победить в борьбе против мониторинга!
Kjempe og vinne kamp mot overvåkning!
Pugnare et pugna vincere versus circumdare custodiere!


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Texteditor QT( c++ )
BeitragVerfasst: Mi 4. Apr 2012, 10:42 
Administrator
Benutzeravatar

Registriert: Mi 8. Jun 2011, 15:57
Beiträge: 723
Wohnort: 127.0.0.1
Karv hat geschrieben:
Das ist ein Textfeld... da kann man was reinschreiben... ergo n "editor" oder n "vi" - speichern is natürlich ne andere Sache - das war übrigens trolling... -.-


Danke für deinen "geistreichen" Beitrag , er war ganz deinem Wissensstand entsprechend - das war übrigens Ironie mit trolling !

übriges gibt es sowas schon :

_________________
nexusfail und Miss Rabiit sind die besten :D


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Neues Thema erstellenAntwort schreiben Seite 1 von 4   [ 39 Beiträge ]
Gehe zu Seite 1, 2, 3, 4  Nächste


Wer ist online?

0 Mitglieder


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron


Powered by phpBB® Forum Software © phpBB Group


Bei iphpbb3.com bekommen Sie ein kostenloses Forum mit vielen tollen Extras
Forum kostenlos einrichten - Hot Topics - Tags
Beliebteste Themen: Erde, Österreich, Wien, USA, NES

Impressum | Datenschutz