Qt主窗口
image.png
italic.png
rotate180.png
paste.png
right.png
undo.png
color.png
justify.png
zoomout.png
redo.png
new.png
rotate90.png
printText.png
center.png
bold.png
copy.png
zoomin.png
underline.png
open.png
rotate90.png
printImage.png
cut.png
left.png
ImageProcessor.pro
QT += core gui printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ImageProcessor
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp \
imgprocessor.cpp \
showwidget.cpp
HEADERS += imgprocessor.h \
showwidget.h
main.cpp
#include "imgprocessor.h"
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QFont f("ZYSong18030",12);
a.setFont(f);
ImgProcessor w;
w.show();
return a.exec();
}
imgprocessor.h
#ifndef IMGPROCESSOR_H
#define IMGPROCESSOR_H
#include <QMainWindow>
#include <QImage>
#include <QLabel>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QComboBox>
#include <QSpinBox>
#include <QToolBar>
#include <QFontComboBox>
#include <QToolButton>
#include <QTextCharFormat>
#include "showwidget.h"
class ImgProcessor : public QMainWindow {
Q_OBJECT
public:
explicit ImgProcessor(QWidget *parent = 0);
void createActions(); //创建动作
void createMenus(); //创建菜单
void createToolBars(); //创建工具栏
void loadFile(QString filename);
void mergeFormat(QTextCharFormat);
protected slots:
void ShowNewFile();
void ShowOpenFile();
void ShowPrintText();
void ShowPrintImage();
void ShowZoomIn();
void ShowZoomOut();
void ShowRotate90();
void ShowRotate180();
void ShowRotate270();
void ShowMirrorVertical();
void ShowMirrorHorizontal();
void ShowFontComboBox(QString comboStr);
void ShowSizeSpinBox(QString spinValue);
void ShowBoldBtn();
void ShowItalicBtn();
void ShowUnderlineBtn();
void ShowColorBtn();
void ShowCurrentFormatChanged(const QTextCharFormat &fmt);
void ShowList(int);
void ShowAlignment(QAction *act);
void ShowCursorPositionChanged();
private:
//文件菜单项
QAction *openFileAction;
QAction *NewFileAction;
QAction *PrintTextAction;
QAction *PrintImageAction;
QAction *exitAction;
//编辑菜单项
QAction *copyAction;
QAction *cutAction;
QAction *pasteAction;
QAction *aboutAction;
QAction *zoomInAction;
QAction *zoomOutAction;
//旋转菜单项
QAction *rotate90Action;
QAction *rotate180Action;
QAction *rotate270Action;
//镜像菜单项
QAction *mirrorVerticalAction;
QAction *mirrorHorizontalAction;
//
QAction *undoAction;
QAction *redoAction;
QActionGroup *actGrp;
QAction *leftAction;
QAction *rightAction;
QAction *centerAction;
QAction *justifyAction;
//各项菜单栏
QMenu *fileMenu;
QMenu *zoomMenu;
QMenu *rotateMenu;
QMenu *mirrorMenu;
QToolBar *fileTool; //工具栏
QToolBar *zoomTool;
QToolBar *rotateTool;
QToolBar *doToolBar;
QLabel *fontLabel1; //字体设置项
QFontComboBox *fontComboBox;
QLabel *fontLabel2;
QComboBox *sizeComboBox;
QToolButton *boldBtn;
QToolButton *italicBtn;
QToolButton *underlineBtn;
QToolButton *colorBtn;
QToolBar *fontToolBar; //字体工具栏
QLabel *listLabel; //排序设置项
QComboBox *listComboBox;
QToolBar *listToolBar; //排序工具栏
QImage img;
QString fileName;
ShowWidget *showWidget;
int scaleNumber;
int rotateNumber;
};
#endif // IMGPROCESSOR_H
imgprocessor.cpp
#include "imgprocessor.h"
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QPrintDialog>
#include <QPrinter>
#include <QPainter>
#include <QColorDialog>
#include <QColor>
#include <QTextList>
#include <QApplication>
#include <cmath>
ImgProcessor::ImgProcessor(QWidget *parent) : QMainWindow(parent) {
setWindowTitle(tr("Easy Word"));
showWidget = new ShowWidget(this);
if(img.load("image.png")) {
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
setCentralWidget(showWidget);
createActions();
createMenus();
createToolBars();
connect(showWidget->text, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(ShowCurrentFormatChanged(QTextCharFormat)));
connect(showWidget->text->document(), SIGNAL(undoAvailable(bool)), redoAction, SLOT(setEnabled(bool)));
connect(showWidget->text->document(), SIGNAL(redoAvailable(bool)), redoAction, SLOT(setEnabled(bool)));
connect(showWidget->text, SIGNAL(cursorPositionChanged()), this, SLOT(ShowCursorPositionChanged()));
scaleNumber = 0;
rotateNumber = 0;
}
void ImgProcessor::createActions() {
//“打开”动作
openFileAction = new QAction(QIcon("open.png"), tr("打开"), this);//(a)
openFileAction->setShortcut(tr("Ctrl+O")); //(b)
openFileAction->setStatusTip(tr("打开一个文件")); //(c)
connect(openFileAction, SIGNAL(triggered()), this, SLOT(ShowOpenFile()));
//“新建”动作
NewFileAction = new QAction(QIcon("new.png"), tr("新建"), this);
NewFileAction->setShortcut(tr("Ctrl+N"));
NewFileAction->setStatusTip(tr("新建一个文件"));
connect(NewFileAction, SIGNAL(triggered()), this, SLOT(ShowNewFile()));
//“打印文本”动作
PrintTextAction = new QAction(QIcon("printText.png"), tr("打印文本"), this);
PrintTextAction->setStatusTip(tr("打印一个文本"));
connect(PrintTextAction, SIGNAL(triggered()), this, SLOT(ShowPrintText()));
//“打印图像”动作
PrintImageAction = new QAction(QIcon("printImage.png"), tr("打印图像"), this);
PrintImageAction->setStatusTip(tr("打印一幅图像"));
connect(PrintImageAction, SIGNAL(triggered()), this, SLOT(ShowPrintImage()));
//“退出”动作
exitAction = new QAction(tr("退出"), this);
exitAction->setShortcut(tr("Ctrl+Q"));
exitAction->setStatusTip(tr("退出程序"));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
//“复制”动作
copyAction = new QAction(QIcon("copy.png"), tr("复制"), this);
copyAction->setShortcut(tr("Ctrl+C"));
copyAction->setStatusTip(tr("复制文件"));
connect(copyAction, SIGNAL(triggered()), showWidget->text, SLOT(copy()));
//“剪切”动作
cutAction = new QAction(QIcon("cut.png"), tr("剪切"), this);
cutAction->setShortcut(tr("Ctrl+X"));
cutAction->setStatusTip(tr("剪切文件"));
connect(cutAction, SIGNAL(triggered()), showWidget->text, SLOT(cut()));
//“粘贴”动作
pasteAction = new QAction(QIcon("paste.png"), tr("粘贴"), this);
pasteAction->setShortcut(tr("Ctrl+V"));
pasteAction->setStatusTip(tr("粘贴文件"));
connect(pasteAction, SIGNAL(triggered()), showWidget->text, SLOT(paste()));
//“关于”动作
aboutAction = new QAction(tr("关于"), this);
connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
//“放大”动作
zoomInAction = new QAction(QIcon("zoomin.png"), tr("放大"), this);
zoomInAction->setStatusTip(tr("放大一张图片"));
connect(zoomInAction, SIGNAL(triggered()), this, SLOT(ShowZoomIn()));
//“缩小”动作
zoomOutAction = new QAction(QIcon("zoomout.png"), tr("缩小"), this);
zoomOutAction->setStatusTip(tr("缩小一张图片"));
connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(ShowZoomOut()));
//实现图像旋转的动作(Action)
//旋转90°
rotate90Action = new QAction(QIcon("rotate90.png"), tr("旋转90°"), this);
rotate90Action->setStatusTip(tr("将一幅图旋转90°"));
connect(rotate90Action, SIGNAL(triggered()), this, SLOT(ShowRotate90()));
//旋转180°
rotate180Action = new QAction(QIcon("rotate180.png"), tr("旋转180°"), this);
rotate180Action->setStatusTip(tr("将一幅图旋转180°"));
connect(rotate180Action, SIGNAL(triggered()), this, SLOT(ShowRotate180()));
//旋转270°
rotate270Action = new QAction(QIcon("rotate270.png"), tr("旋转270°"), this);
rotate270Action->setStatusTip(tr("将一幅图旋转270°"));
connect(rotate270Action, SIGNAL(triggered()), this, SLOT(ShowRotate270()));
//实现图像镜像的动作(Action)
//纵向镜像
mirrorVerticalAction = new QAction(QIcon("mirrorVertical.png"), tr ("纵向镜像"), this);
mirrorVerticalAction->setStatusTip(tr("对一幅图做纵向镜像"));
connect(mirrorVerticalAction, SIGNAL(triggered()), this, SLOT(ShowMirrorVertical()));
//横向镜像
mirrorHorizontalAction = new QAction(QIcon("mirrorHorizontal.png"), tr("横向镜像"), this);
mirrorHorizontalAction->setStatusTip(tr("对一幅图做横向镜像"));
connect(mirrorHorizontalAction, SIGNAL(triggered()), this, SLOT(ShowMirrorHorizontal()));
//实现撤销和恢复的动作(Action)
//撤销和恢复
undoAction = new QAction(QIcon("undo.png"), tr("撤销"), this);
connect(undoAction, SIGNAL(triggered()), showWidget->text, SLOT(undo()));
redoAction = new QAction(QIcon("redo.png"), tr("重做"), this);
connect(redoAction, SIGNAL(triggered()), showWidget->text, SLOT(redo()));
//排序:左对齐、右对齐、居中和两端对齐
actGrp = new QActionGroup(this);
leftAction = new QAction(QIcon("left.png"), tr("左对齐"), actGrp);
leftAction->setCheckable(true);
rightAction = new QAction(QIcon("right.png"), tr("右对齐"), actGrp);
rightAction->setCheckable(true);
centerAction = new QAction(QIcon("center.png"), tr("居中"), actGrp);
centerAction->setCheckable(true);
justifyAction = new QAction(QIcon("justify.png"), tr("两端对齐"), actGrp);
justifyAction->setCheckable(true);
connect(actGrp, SIGNAL(triggered(QAction*)), this, SLOT(ShowAlignment(QAction*)));
}
void ImgProcessor::createMenus() {
//文件菜单
fileMenu = menuBar()->addMenu(tr("文件")); //(a)
fileMenu->addAction(openFileAction); //(b)
fileMenu->addAction(NewFileAction);
fileMenu->addAction(PrintTextAction);
fileMenu->addAction(PrintImageAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
//缩放菜单
zoomMenu = menuBar()->addMenu(tr("编辑"));
zoomMenu->addAction(copyAction);
zoomMenu->addAction(cutAction);
zoomMenu->addAction(pasteAction);
zoomMenu->addAction(aboutAction);
zoomMenu->addSeparator();
zoomMenu->addAction(zoomInAction);
zoomMenu->addAction(zoomOutAction);
//旋转菜单
rotateMenu = menuBar()->addMenu(tr("旋转"));
rotateMenu->addAction(rotate90Action);
rotateMenu->addAction(rotate180Action);
rotateMenu->addAction(rotate270Action);
//镜像菜单
mirrorMenu = menuBar()->addMenu(tr("镜像"));
mirrorMenu->addAction(mirrorVerticalAction);
mirrorMenu->addAction(mirrorHorizontalAction);
}
void ImgProcessor::createToolBars() {
//文件工具条
fileTool = addToolBar("File"); //(a)
fileTool->addAction(openFileAction); //(b)
fileTool->addAction(NewFileAction);
fileTool->addAction(PrintTextAction);
fileTool->addAction(PrintImageAction);
//编辑工具条
zoomTool = addToolBar("Edit");
zoomTool->addAction(copyAction);
zoomTool->addAction(cutAction);
zoomTool->addAction(pasteAction);
zoomTool->addSeparator();
zoomTool->addAction(zoomInAction);
zoomTool->addAction(zoomOutAction);
//旋转工具条
rotateTool = addToolBar("rotate");
rotateTool->addAction(rotate90Action);
rotateTool->addAction(rotate180Action);
rotateTool->addAction(rotate270Action);
//撤销和重做工具条
doToolBar = addToolBar("doEdit");
doToolBar->addAction(undoAction);
doToolBar->addAction(redoAction);
//字体工具条
fontLabel1 = new QLabel(tr("字体:"));
fontComboBox = new QFontComboBox;
fontComboBox->setFontFilters(QFontComboBox::ScalableFonts);
fontLabel2 = new QLabel(tr("字号:"));
sizeComboBox = new QComboBox;
foreach(int size, QFontDatabase::standardSizes())
sizeComboBox->addItem(QString::number(size));
boldBtn = new QToolButton;
boldBtn->setIcon(QIcon("bold.png"));
boldBtn->setCheckable(true);
italicBtn = new QToolButton;
italicBtn->setIcon(QIcon("italic.png"));
italicBtn->setCheckable(true);
underlineBtn = new QToolButton;
underlineBtn->setIcon(QIcon("underline.png"));
underlineBtn->setCheckable(true);
colorBtn = new QToolButton;
colorBtn->setIcon(QIcon("color.png"));
colorBtn->setCheckable(true);
connect(fontComboBox, SIGNAL(activated(QString)), this, SLOT(ShowFontComboBox(QString)));
connect(sizeComboBox, SIGNAL(activated(QString)), this, SLOT(ShowSizeSpinBox(QString)));
connect(boldBtn, SIGNAL(clicked()), this, SLOT(ShowBoldBtn()));
connect(italicBtn, SIGNAL(clicked()), this, SLOT(ShowItalicBtn()));
connect(underlineBtn, SIGNAL(clicked()), this, SLOT(ShowUnderlineBtn()));
connect(colorBtn, SIGNAL(clicked()), this, SLOT(ShowColorBtn()));
fontToolBar = addToolBar("Font");
fontToolBar->addWidget(fontLabel1);
fontToolBar->addWidget(fontComboBox);
fontToolBar->addWidget(fontLabel2);
fontToolBar->addWidget(sizeComboBox);
fontToolBar->addSeparator();
fontToolBar->addWidget(boldBtn);
fontToolBar->addWidget(italicBtn);
fontToolBar->addWidget(underlineBtn);
fontToolBar->addSeparator();
fontToolBar->addWidget(colorBtn);
//排序工具条
listLabel = new QLabel(tr("排序"));
listComboBox = new QComboBox;
listComboBox->addItem("Standard");
listComboBox->addItem("QTextListFormat::ListDisc");
listComboBox->addItem("QTextListFormat::ListCircle");
listComboBox->addItem("QTextListFormat::ListSquare");
listComboBox->addItem("QTextListFormat::ListDecimal");
listComboBox->addItem("QTextListFormat::ListLowerAlpha");
listComboBox->addItem("QTextListFormat::ListUpperAlpha");
listComboBox->addItem("QTextListFormat::ListLowerRoman");
listComboBox->addItem("QTextListFormat::ListUpperRoman");
connect(listComboBox, SIGNAL(activated(int)), this, SLOT(ShowList(int)));
listToolBar =addToolBar("list");
listToolBar->addWidget(listLabel);
listToolBar->addWidget(listComboBox);
listToolBar->addSeparator();
listToolBar->addActions(actGrp->actions());
}
void ImgProcessor::ShowNewFile() {
ImgProcessor *newImgProcessor = new ImgProcessor;
newImgProcessor->show();
}
void ImgProcessor::ShowOpenFile() {
fileName = QFileDialog::getOpenFileName(this);
if(!fileName.isEmpty()) {
if(showWidget->text->document()->isEmpty()){
loadFile(fileName);
} else{
ImgProcessor *newImgProcessor = new ImgProcessor;
newImgProcessor->show();
newImgProcessor->loadFile(fileName);
}
}
}
void ImgProcessor::loadFile(QString filename) {
QFile file(filename);
if(file.open(QIODevice::ReadOnly|QIODevice::Text)) {
QTextStream textStream(&file);
while(!textStream.atEnd()) {
showWidget->text->append(textStream.readLine());
}
}
}
void ImgProcessor::ShowPrintText() {
QPrinter printer;
QPrintDialog printDialog(&printer, this);
if(printDialog.exec()) {
QTextDocument *doc = showWidget->text->document();
doc->print(&printer);
}
}
void ImgProcessor::ShowPrintImage() {
QPrinter printer;
QPrintDialog printDialog(&printer, this);
if(printDialog.exec()) {
QPainter painter(&printer); //(c)
QRect rect = painter.viewport(); //获得QPainter对象的视图矩形区域
QSize size = img.size(); //获得图像的大小
/* 按照图形的比例大小重新设置视图矩形区域 */
size.scale(rect.size(), Qt::KeepAspectRatio);
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
painter.setWindow(img.rect()); //设置QPainter窗口大小为图像的大小
painter.drawImage(0, 0, img); //打印图像
}
}
void ImgProcessor::ShowZoomIn() {
if(img.isNull()) //有效性判断
return;
scaleNumber++;
QMatrix matrix; //声明一个QMatrix类的实例
matrix.scale(pow(2, scaleNumber), pow(2, scaleNumber));
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img.transformed(matrix)));
}
void ImgProcessor::ShowZoomOut() {
if(img.isNull())
return;
scaleNumber--;
QMatrix matrix;
matrix.scale(pow(2, scaleNumber), pow(2, scaleNumber));
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img.transformed(matrix)));
}
void ImgProcessor::ShowRotate90() {
if(img.isNull())
return;
rotateNumber += 1;
QMatrix matrix;
matrix.rotate(90*rotateNumber);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img.transformed(matrix)));
}
void ImgProcessor::ShowRotate180() {
if(img.isNull())
return;
rotateNumber += 2;
QMatrix matrix;
matrix.rotate(90*rotateNumber);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img.transformed(matrix)));
}
void ImgProcessor::ShowRotate270() {
if(img.isNull())
return;
rotateNumber += 3;
QMatrix matrix;
matrix.rotate(90*rotateNumber);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img.transformed(matrix)));
}
void ImgProcessor::ShowMirrorVertical() {
if(img.isNull())
return;
img = img.mirrored(false, true);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
void ImgProcessor::ShowMirrorHorizontal() {
if(img.isNull())
return;
img = img.mirrored(true,false);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
void ImgProcessor::ShowFontComboBox(QString comboStr) {
QTextCharFormat fmt; //创建一个QTextCharFormat对象
fmt.setFontFamily(comboStr); //选择的字体名称设置给QTextCharFormat对象
mergeFormat(fmt); //将新的格式应用到光标选区内的字符
}
void ImgProcessor::mergeFormat(QTextCharFormat format) {
QTextCursor cursor = showWidget->text->textCursor();
//获得编辑框中的光标
if(!cursor.hasSelection()) //(a)
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format); //(b)
showWidget->text->mergeCurrentCharFormat(format); //(c)
}
void ImgProcessor::ShowSizeSpinBox(QString spinValue) {
QTextCharFormat fmt;
fmt.setFontPointSize(spinValue.toFloat());
showWidget->text->mergeCurrentCharFormat(fmt);
}
void ImgProcessor::ShowBoldBtn() {
QTextCharFormat fmt;
fmt.setFontWeight(boldBtn->isChecked()?QFont::Bold:QFont::Normal);
showWidget->text->mergeCurrentCharFormat(fmt);
}
void ImgProcessor::ShowItalicBtn() {
QTextCharFormat fmt;
fmt.setFontItalic(italicBtn->isChecked());
showWidget->text->mergeCurrentCharFormat(fmt);
}
void ImgProcessor::ShowUnderlineBtn() {
QTextCharFormat fmt;
fmt.setFontUnderline(underlineBtn->isChecked());
showWidget->text->mergeCurrentCharFormat(fmt);
}
void ImgProcessor::ShowColorBtn() {
QColor color = QColorDialog::getColor(Qt::red, this); //(a)
if(color.isValid()) {
QTextCharFormat fmt;
fmt.setForeground(color);
showWidget->text->mergeCurrentCharFormat(fmt);
}
}
void ImgProcessor::ShowCurrentFormatChanged(const QTextCharFormat &fmt) {
fontComboBox->setCurrentIndex(fontComboBox->findText(fmt.fontFamily()));
sizeComboBox->setCurrentIndex(sizeComboBox->findText(QString::number(fmt.fontPointSize())));
boldBtn->setChecked(fmt.font().bold());
italicBtn->setChecked(fmt.fontItalic());
underlineBtn->setChecked(fmt.fontUnderline());
}
void ImgProcessor::ShowAlignment(QAction *act) {
if(act==leftAction)
showWidget->text->setAlignment(Qt::AlignLeft);
else if(act==rightAction)
showWidget->text->setAlignment(Qt::AlignRight);
else if(act==centerAction)
showWidget->text->setAlignment(Qt::AlignCenter);
else if(act==justifyAction)
showWidget->text->setAlignment(Qt::AlignJustify);
}
void ImgProcessor::ShowCursorPositionChanged() {
if(showWidget->text->alignment()==Qt::AlignLeft)
leftAction->setChecked(true);
else if(showWidget->text->alignment()==Qt::AlignRight)
rightAction->setChecked(true);
else if(showWidget->text->alignment()==Qt::AlignCenter)
centerAction->setChecked(true);
else if(showWidget->text->alignment()==Qt::AlignJustify)
justifyAction->setChecked(true);
}
void ImgProcessor::ShowList(int index) {
//获得编辑框的QTextCursor对象指针
QTextCursor cursor = showWidget->text->textCursor();
if(index!=0) {
QTextListFormat::Style style=QTextListFormat::ListDisc;//(a)
switch(index) {
default:
case 1:
style=QTextListFormat::ListDisc; break;
case 2:
style=QTextListFormat::ListCircle; break;
case 3:
style=QTextListFormat::ListSquare; break;
case 4:
style=QTextListFormat::ListDecimal; break;
case 5:
style=QTextListFormat::ListLowerAlpha; break;
case 6:
style=QTextListFormat::ListUpperAlpha; break;
case 7:
style=QTextListFormat::ListLowerRoman; break;
case 8:
style=QTextListFormat::ListUpperRoman; break;
}
/* 设置缩进值 */ //(b)
cursor.beginEditBlock();
QTextBlockFormat blockFmt=cursor.blockFormat();
QTextListFormat listFmt;
if(cursor.currentList()){
listFmt= cursor.currentList()->format();
} else {
listFmt.setIndent(blockFmt.indent()+1);
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
listFmt.setStyle(style);
cursor.createList(listFmt);
cursor.endEditBlock();
} else {
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-1);
cursor.mergeBlockFormat(bfmt);
}
}
showwidget.h
#ifndef SHOWWIDGET_H
#define SHOWWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QTextEdit>
#include <QImage>
#include <QHBoxLayout>
class ShowWidget : public QWidget {
Q_OBJECT
public:
explicit ShowWidget(QWidget *parent = 0);
QImage img;
QLabel *imageLabel;
QTextEdit *text;
private:
QHBoxLayout *mainLayout;
};
#endif // SHOWWIDGET_H
showwidget.cpp
#include "showwidget.h"
ShowWidget::ShowWidget(QWidget *parent) : QWidget(parent) {
imageLabel = new QLabel;
imageLabel->setScaledContents(true);
text = new QTextEdit;
mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(imageLabel);
mainLayout->addWidget(text);
}