zoukankan      html  css  js  c++  java
  • notepad

    #ifndef ABOUT_H
    #define ABOUT_H
    
    
    #include <QDialog>
    #include <QMovie>
    namespace Ui {
    class about;
    }
    
    
    class about : public QDialog
    {
        Q_OBJECT
    
    
    public:
        explicit about(QWidget *parent = 0);
        ~about();
    private slots:
        void moviestart();
        void moviestop();
    private:
        Ui::about *ui;
        QMovie *movie;
    };
    
    
    #endif // ABOUT_H

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    
    #include <QMainWindow>
    #include "about.h"
    namespace Ui {
    class MainWindow;
    }
    
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    protected:
        void closeEvent(QCloseEvent *event);
    private slots:
        void Newfile();
        void Openfile();
        void Savefile();
        void SaveAsfile();
        void PrintFile();
        void setFont();
        void setColor();
        void getDate();
        void aboutWebsiteSlot();
        void aboutSoftwareSlot();
    private:
        Ui::MainWindow *ui;
        QString savefilename;
    };
    
    
    #endif // MAINWINDOW_H

    #include "about.h"
    #include "ui_about.h"
    #include <QDebug>
    about::about(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::about)
    {
        ui->setupUi(this);
        //实例化
        this->movie = new QMovie("pe_4.gif");
        ui->movie_label->setMovie(movie);
        this->movie->start();
        qDebug()<<"this git have frame"<<movie->frameCount();
        this->connect(ui->startB,SIGNAL(clicked()),this,SLOT(moviestart()));
        QObject::connect(ui->stopB,SIGNAL(clicked()),this,SLOT(moviestop()));
    }
    
    
    about::~about()
    {
        delete ui;
    }
    
    
    void about::moviestart()
    {
        this->movie->start();
    }
    
    
    void about::moviestop()
    {
        this->movie->stop();
    }
    /*  打开--文件路径--filedialog--Qfile.open---QTextStream
    文件属性
     Qfile  setFileName
     QFileDialog getOpenfileName(this,"open file 标题","路径","过滤")
     QDir
     QTextStream
    
    
     Gtk-Message: 09:25:06.890: GtkDialog mapped without a transient parent. This is discouraged.
    
    
    
    
     QColor
     QFront
     QFrontDialog
    QDateTime 格式  hh:mm YYYY/M/dd
                YYYY/M/dd hh:mm
    添加图标:(放在工程目录下)
    美工: 添加资源文件  --添加新文件---QT---rescurse file---res(名称)--添加前缀(add prefix)--添加文件(add file)--ui --edit--icon  --choice
    
    
    ui->passLineEdit->setEchoModel(QLineEdit::Password)  ;  //非明文显示
    
    
    全局的qApp  QCoreApplication::instance();
    应用程序实例化指针
    
    
    
    
    OllyDBG_1.8
    
    
    
    
    关闭事件  dialog.exe()返回值
    
    
    打包:
     release 编译
     ldd 查看依赖
     导出依赖
    
    
    
    
    
    
     */
    
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QDebug>
    #include <QFileDialog>
    #include <QMessageBox>
    #include <QDir>
    #include <QTextStream>
    
    
    #include <QFontDialog>
    #include <QFont>
    #include <QColorDialog>
    #include <QColor>
    #include <QDateTime>
    
    
    #include <QUrl>  //地址
    #include <QDesktopServices>  //访问桌面服务额
    #include <QSound>
    
    
    #include <QCloseEvent>
    //所有的事件都是受保护的  QWiget
    
    
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        this->setWindowTitle("Unititled --noted");   //设置标题
        //fimemenu
     QSound::play("tts.wav");
        QObject::connect(ui->actionNewFile,SIGNAL(triggered()),this,SLOT(Newfile()));
        QObject::connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(Openfile()));
        QObject::connect(ui->actionSave,SIGNAL(triggered()),this,SLOT(Savefile()));
         QObject::connect(ui->actionasSave,SIGNAL(triggered()),this,SLOT(SaveAsfile()));
        QObject::connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(close()));
        //edit
        QObject::connect(ui->udaction,SIGNAL(triggered()),ui->textEdit,SLOT(undo()));
        QObject::connect(ui->rdaction,SIGNAL(triggered()),ui->textEdit,SLOT(redo()));
        QObject::connect(ui->cpaction,SIGNAL(triggered()),ui->textEdit,SLOT(copy()));
        QObject::connect(ui->cuaction,SIGNAL(triggered()),ui->textEdit,SLOT(cut()));
        QObject::connect(ui->psaction,SIGNAL(triggered()),ui->textEdit,SLOT(paste()));
        QObject::connect(ui->allaction,SIGNAL(triggered()),ui->textEdit,SLOT(selectAll()));
    
    
        QObject::connect(ui->coloraction,SIGNAL(triggered()),this,SLOT(setColor()));
        QObject::connect(ui->fontaction,SIGNAL(triggered()),this,SLOT(setFont()));
        QObject::connect(ui->dtaction,SIGNAL(triggered()),this,SLOT(getDate()));
        QObject::connect(ui->action_QT_Q,SIGNAL(triggered()),qApp,SLOT(aboutQt()));
        QObject::connect(ui->action_W,SIGNAL(triggered()),this,SLOT(aboutWebsiteSlot()));
        QObject::connect(ui->action_S,SIGNAL(triggered()),this,SLOT(aboutSoftwareSlot()));
    
    
    
    
    
    
    }
    
    
    MainWindow::~MainWindow()
    {
        delete ui;
        // 对像  垃圾回收机制  只针对图形对象  容器  qtgui
        //qtCore  核心模块  需要手动释放
    }
    
    
    void MainWindow::closeEvent(QCloseEvent *event)
    {
        if(ui->textEdit->document()->isModified())
            {
    
    
            QMessageBox msgBox;
              msgBox.setText("文件以修改。");
              msgBox.setInformativeText("是否需要保存?");
              msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
              msgBox.setDefaultButton(QMessageBox::Save);
              int ret = msgBox.exec();
              switch (ret) {
                 case QMessageBox::Save:
                     // Save was clicked
                  this->Savefile();
                     break;
                 case QMessageBox::Discard:
                     // Don't Save was clicked
                  event->accept();
                     break;
                 case QMessageBox::Cancel:
                     // Cancel was clicked
                  event->ignore();
                     break;
                 default:
                     // should never be reached
                     break;
               }
        }
    }
    
    
    void MainWindow::Newfile()
    {
        //判断是佛改变
        if(ui->textEdit->document()->isModified())
        {
    
    
            ui->textEdit->clear();
        }
        else
        {
            //清空编辑区内容
            ui->textEdit->clear();
    
    
            //改变窗口
            this->setWindowTitle("Untitle.txt -----selen");
        }
    }
    //打开文件
    void MainWindow::Openfile()
    {
        //获得文件名                                    标题                起始路径
        savefilename = QFileDialog::getOpenFileName(this,"Open File",QDir::currentPath());
        qDebug()<<savefilename;
        if(savefilename.isEmpty())  //isNULL
        {
    
    
            QMessageBox::information(this,"Error Message","Please Slect a Textfile");
            return;
        }
        //文件指针
        QFile *file = new QFile;
        file->setFileName(savefilename);
        bool ok=file->open(QIODevice::ReadOnly);
    
    
        if(ok)
        {
            //打开文件   流 内存   对流操作快   read  write  是对磁盘操作
            //
            QTextStream in(file);
            ui->textEdit->setText(in.readAll());  //
            file->close();
            this->setWindowTitle(savefilename+"-----selen");
            delete file;  //属于QCore 模块需要手动释放   图形类对象有一是QTGUI 有一个守护指针自动释放
        }
        else
        {
            //                                     标题                   信息
            QMessageBox::information(this,"Error Message","File open error"+file->errorString());
            return ;
        }
    }
    
    
    void MainWindow::SaveAsfile()
    {
        savefilename = QFileDialog::getSaveFileName(this,"Save File",QDir::currentPath());
        if(savefilename.isEmpty())
        {
    
    
            QMessageBox::information(this,"Error Message","Please Select a Text File.");
            return ;
        }
    
    
        //创建文件对象
        QFile *file = new QFile;
        //设置文件名称
        file->setFileName(savefilename);
        bool ok = file->open(QIODevice::WriteOnly);
        if(ok)
        {
            QTextStream  out(file);
            //cout <<
            out<<ui->textEdit->toPlainText();  //转换为纯文本
            file->close();
            delete file;//删除文件对象
    
    
        }
        else
        {
    
    
            QMessageBox::information(this,"Error Message","Save File Error"+file->errorString());
            return ;
        }
    
    
    
    
    
    
    }
    
    
    void MainWindow::Savefile()
    {
        //当前
        if(savefilename.isEmpty())
        {
    
    
            this->SaveAsfile();
        }
        else
        {
            QFile *file = new QFile;
            //设置文件名称
            file->setFileName(savefilename);
            bool ok = file->open(QIODevice::WriteOnly);
            if(ok)
            {
                QTextStream  out(file);
                //cout <<
                out<<ui->textEdit->toPlainText();  //转换为纯文本
                file->close();
                //设置当前标题
                this->setWindowTitle(savefilename+"-----selen");
                delete file;//删除文件对象
    
    
            }
    
    
        }
    }
    
    
    void MainWindow::PrintFile()
    {
        //PrintDialog
    }
    
    
    void MainWindow::setFont()
    {
        //get user select font
        bool ok;
        QFont font = QFontDialog::getFont(&ok,this);
        if(ok)
        {
            ui->textEdit->setFont(font);
    
    
        }
        else
        {
            QMessageBox::information(this,"Error Message","Error Set font!!  ");
        }
    }
    
    
    void MainWindow::setColor()
    {  //创建颜色对象
        QColor color = QColorDialog::getColor(Qt::red,this);
        if(color.isValid())
        {
    
    
            ui->textEdit->setTextColor(color);
        }
        else
        {
    
    
            QMessageBox::information(this,"Error Massage","Color is isValid!!");
        }
    }
    
    
    void MainWindow::getDate()
    {
        QDateTime current = QDateTime::currentDateTime();
        //按照指定格式 转化为字符串
        QString time = current.toString("hh:mm yyyy/M/dd");
        ui->textEdit->append(time);
    }
    
    
    void MainWindow::aboutWebsiteSlot()
    {//直接打开  启动桌面服务
        QDesktopServices::openUrl(QUrl("https://home.cnblogs.com/u/countryboy666/"));
    }
    
    
    void MainWindow::aboutSoftwareSlot()
    {
        about *dialog = new about;
        dialog->show();
        //dialog->exec();
    
    
    }
    
    
    
    
    
    


    
    
    #include "mainwindow.h"

    #include <QApplication>
    #include <QPixmap>
    #include <QSplashScreen>
    #include <QTime>
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
                //加载图片
              QPixmap pixmap("1bitX.png");
              //显示屏幕
              QSplashScreen splash(pixmap);
              splash.show();
              //
             // for(long long index = 0;index<8000000000000000000;index++);
          //   sleep(1);
           //处理事情
           //延时
              QTime t;
              t.start();
              while(t.elapsed()<1000)
                  QCoreApplication::processEvents();
                 MainWindow w;
                 w.show();
    
    
                 splash.finish(&w);
    
    
        return a.exec();
    }




  • 相关阅读:
    ReSharper Tips—GotoImplementation
    Possible multiple enumeration of IEnumerable
    Hello, Razor!
    自话自说——POI使用需要注意一个地方
    css中怎么设置透明度的问题
    记录排查国标直播流播放卡顿的问题
    互联网上做广告的优点
    C#、.Net经典面试题集锦(一)
    什么是MFC
    C/S与B/S 的区别
  • 原文地址:https://www.cnblogs.com/countryboy666/p/11066805.html
Copyright © 2011-2022 走看看