Qt-WPS⽂本编辑器(WPS⽂档打印预览)WPS⽂档打印预览
mainwind.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include<QMainWindow>
#include"childwnd.h"
#include<QSignalMapper>
#include<QWidget>
#include<QMdiSubWindow>
#include<QPrinter>
namespace Ui {
class MainWindow;
}
class MainWindow :public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent =0); ~MainWindow();
void initMainWindow();
void docNew();
void docOpen();
void docSave();
void docSaveAs();
void docPrint();
void docPrintPreview();
void docUndo();
void docRedo();
void docCut();
void docCopy();
void docPaste();
void textBold();
void textItalic();
void textUnderline();
void textFamily(const QString &fmly); void textSize(const QString &ps);
void textColor();
void paraStyle(int nStyle);
private slots:
void on_newAction_triggered();
void refreshMenus();
void addSubWndListMenu();
void on_closeAction_triggered();
void on_closeAllAction_triggered();
void on_titleAction_triggered();
void on_cascadeAction_triggered();
void on_nextAction_triggered();
void on_previousAction_triggered();
void setActiveSubWindow(QWidget *wnd); void on_openAction_triggered();
void on_saveAction_triggered();
void on_saveAsAction_triggered();
void on_undoAction_triggered();
void on_redoAction_triggered();
void on_cutAction_triggered();
void on_copyAction_triggered();
void on_pasteAction_triggered();
void on_boldAction_triggered();
void on_italicAction_triggered();
void on_underlineAction_triggered();
void on_fontComboBox_activated(const QString &arg1); void on_sizeComboBox_activated(const QString &arg1); void on_leftAlignAction_triggered();
void on_rightlignAction_triggered();
void on_centerAction_triggered();
void on_justifyAction_triggered();
void on_colorAction_triggered();
void on_comboBox_activated(int index);
void on_printAction_triggered();
void printPreview(QPrinter *printer);
void on_printPreviewAction_triggered();
protected:
void closeEvent(QCloseEvent *event);
private:
void formatEnabled();
ChildWnd*activateChildWnd();
QMdiSubWindow *findChildWnd(const QString& docName);
private:
Ui::MainWindow *ui;
QSignalMapper *m_WndMapper;//信号映射器
fontweight属性bold
};
#endif// MAINWINDOW_H
mainwindow.cpp
#include"mainwindow.h"
#include"ui_mainwindow.h"
#include"childwnd.h"
#include<QFontDatabase>
#include<QMdiSubWindow>
#include<QCloseEvent>
#include<QFileDialog>
#include<QColorDialog>
#include<QtPrintSupport/QPrinter>
#include<QtPrintSupport/QPrintDialog>
#include<QPrintPreviewDialog>
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
initMainWindow();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initMainWindow()
{
//初始化字号列表项
QFontDatabase fontdb;
foreach(int fontsize, fontdb.standardSizes())
{
ui->sizeComboBox->addItem(QString::number(fontsize));
}
QFont defFont;//当前应⽤程序默认的字体
QString sFontSize;
int defFontSize;//当前应⽤程序默认字体的字号
int defFontindex;//当前字号在组合框中的索引号
defFont = QApplication::font();
defFontSize = defFont.pointSize();
sFontSize = QString::number(defFontSize);
defFontindex = ui->sizeComboBox->findText(sFontSize);
ui->sizeComboBox->setCurrentIndex(defFontindex);
//设置多⽂档区域滚动条
ui->mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
refreshMenus();
connect(ui->mdiArea,&QMdiArea::subWindowActivated,this,&MainWindow::refreshMenus);
addSubWndListMenu();
connect(ui->menu_W,&QMenu::aboutToShow,this,&MainWindow::addSubWndListMenu);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。