#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "user.h"
#include <QButtonGroup>
#include <QFontDialog>
MainWindow::MainWindow(QString name,QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("我的邮箱");
//连接listWidget和stackedWidget
connect(ui->listWidget,SIGNAL(currentRowChanged(int)),ui->stackedWidget,SLOT(setCurrentIndex(int)));
user = new User(name);
init_sendLetter();
//tableWidget布局
init_tableWidget();
init_person();
timer = new QTimer();
timer->start(10000);
connect(timer, SIGNAL(timeout()),this, SLOT(updateTime()));
//添加表内信息
display(user->username);
}
/**
* 刷新tableWidget
*/
void MainWindow::updateTime()
{
display(user->username);
init_person();
}
MainWindow::~MainWindow()
{
delete ui;
}
/**
* 个人信息
*/
void MainWindow::init_person()
{
QSqlQuery qry;
qry.prepare( "SELECT * from user WHERE userid = '"+user->username+"' " );
if( !qry.exec() )
qDebug() << qry.lastError();
else
qDebug( "SELECT!" );
qry.next();
ui->label_person_id->setText(user->username);
ui->label_person_name->setText(qry.value(4).toString());
ui->label_person_address->setText(qry.value(5).toString());
ui->label_person_phone->setText(qry.value(6).toString());
ui->label_person_time->setText(qry.value(7).toString());
if(qry.value(8).toString()!="") ui->label_18->setStyleSheet("\nborder-image: url("+qry.value(8).toString()+");");
if(qry.value(4).toString()!=""){
ui->label_firstPage_name->setText(qry.value(4).toString()+",您好");
}
else{
ui->label_firstPage_name->setText(user->username+",您好");
}
}
void MainWindow::init_sendLetter()
{
MainLayout = new QVBoxLayout(this);
toplayout = new QHBoxLayout();
toplayout->addWidget(ui->Btn_send);
toplayout->addWidget(ui->Btn_preview);
toplayout->addWidget(ui->Btn_draft);
toplayout->addWidget(ui->Btn_cancel);
toplayout->addStretch();
toplayout->addWidget(ui->Btn_resend);
toplayout->addWidget(ui->Btn_sendsecret);
toplayout->addWidget(ui->Btn_qfdx);
toplayout->addWidget(ui->Btn_invite);
middlelayout = new QGridLayout;
middlelayout->addWidget(ui->label_reciever,0,0);
middlelayout->addWidget(ui->Editor_reciever,0,1);
middlelayout->addWidget(ui->label_theme,1,0);
middlelayout->addWidget(ui->Editor_theme,1,1);
Buttonlayout = new QHBoxLayout();
fontLabel1 = new QLabel(tr("字体:"));
fontComboBox = new QFontComboBox;
fontComboBox->setFontFilters(QFontComboBox::ScalableFonts);
fontLabel2 = new QLabel(tr("字号:"));
sizeComboBox = new QComboBox;
QFontDatabase db;
foreach(int size, db.standardSizes())
{
sizeComboBox->addItem(QString::number(size));
}
QSize size(24,24);
boldBtn = new QToolButton;
boldBtn->setIcon(QIcon(":/res/bold.PNG"));
boldBtn->setCheckable(true);
boldBtn->setIconSize(size);
boldBtn->setAutoRaise(true);
italicBtn = new QToolButton;
italicBtn->setIcon(QIcon(":/res/italic.PNG"));
italicBtn->setCheckable(true);
italicBtn->setIconSize(size);
italicBtn->setAutoRaise(true);
underlineBtn = new QToolButton;
underlineBtn->setIcon(QIcon(":/res/underline.PNG"));
underlineBtn->setCheckable(true);
underlineBtn->setIconSize(size);
underlineBtn->setAutoRaise(true);
colorBtn = new QToolButton;
colorBtn->setIcon(QIcon(":/res/color.PNG"));
colorBtn->setIconSize(size);
colorBtn->setAutoRaise(true);
Btgrp2 = new QButtonGroup;
//undo/redo Action
undoAction = new QToolButton;
undoAction->setIcon(QIcon(":/res/undo.PNG"));
undoAction->setIconSize(size);
undoAction->setAutoRaise(true);
Btgrp2->addButton(undoAction,1);
redoAction= new QToolButton;
redoAction->setIcon(QIcon(":/res/redo.PNG"));
redoAction->setIconSize(size);
redoAction->setAutoRaise(true);
Btgrp2->addButton(redoAction,2);
connect(Btgrp2,SIGNAL(buttonClicked(int)),this,SLOT(unredo(int)));
//排版
Btgrp = new QButtonGroup;
leftAction= new QToolButton;
leftAction->setIcon(QIcon(":/res/left.PNG"));
leftAction->setCheckable(true);
leftAction->setIconSize(size);
leftAction->setAutoRaise(true);
Btgrp->addButton(leftAction,1);
rightAction= new QToolButton;
rightAction->setIcon(QIcon(":/res/right.PNG"));
rightAction->setCheckable(true);
rightAction->setIconSize(size);
rightAction->setAutoRaise(true);
Btgrp->addButton(rightAction,2);
centerAction= new QToolButton;
centerAction->setIcon(QIcon(":/res/center.PNG"));
centerAction->setCheckable(true);
centerAction->setIconSize(size);
centerAction->setAutoRaise(true);
Btgrp->addButton(centerAction,3);
justifyAction= new QToolButton;
justifyAction->setIcon(QIcon(":/res/justify.PNG"));
justifyAction->setCheckable(true);
justifyAction->setIconSize(size);
justifyAction->setAutoRaise(true);
Btgrp->addButton(justifyAction,4);
connect(Btgrp,SIGNAL(buttonClicked(int)),this,SLOT(ShowAlignment(int)));
Buttonlayout->addWidget(boldBtn);
Buttonlayout->addWidget(italicBtn);
Buttonlayout->addWidget(underlineBtn);
Buttonlayout->addWidget(colorBtn);
Buttonlayout->addWidget(leftAction);
Buttonlayout->addWidget(centerAction);
Buttonlayout->addWidget(rightAction);
Buttonlayout->addWidget(justifyAction);
Buttonlayout->addWidget(fontLabel2);
Buttonlayout->addWidget(sizeComboBox);
Buttonlayout->addWidget(fontLabel1);
Buttonlayout->addWidget(fontComboBox);
// Buttonlayout->addWidget(action);
Buttonlayout->addWidget(undoAction);
Buttonlayout->addWidget(redoAction);
Buttonlayout->addWidget(ui->toolButton);
Buttonlayout->addWidget(ui->Btn_add);
Buttonlayout->addStretch();
buttomlayout = new QHBoxLayout();
buttomlayout->addWidget(ui->Btn_send_2);
buttomlayout->addWidget(ui->Btn_cancel_2);
buttomlayout->addStretch();
MainLayout->addLayout(toplayout);
MainLayout->addLayout(middlelayout);
MainLayout->addLayout(Buttonlayout);
MainLayout->addWidget(ui->textEdit);
MainLayout->addWidget(ui->label_sender);
MainLayout->addLayout(buttomlayout);
ui->page_Writeletter->setLayout(MainLayout);
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(showUnderlineButton()));
connect(colorBtn,SIGNAL(clicked()),this,SLOT(ShowColorBtn()));
connect( ui->textEdit, SIGNAL( currentCharFormatChanged( const QTextCharFormat & ) ), this, SLOT( ShowCurrentFormatChanged(const QTextCharFormat&)));
connect(ui->Btn_send,SIGNAL(clicked()),this,SLOT(button_send()));
connect(ui->Btn_send_2,SIGNAL(clicked()),this,SLOT(button_send()));
}
void MainWindow::ShowBoldBtn()
{
QTextCharFormat fmt;
fmt.setFontWeight(boldBtn->isChecked()?QFont::Bold:QFont::Normal);
ui->textEdit->mergeCurrentCharFormat(fmt);
}
void MainWindow::ShowItalicBtn()
{
QTextCharFormat fmt;
fmt.setFontItalic(italicBtn->isChecked());
ui->textEdit->mergeCurrentCharFormat(fmt);
}
void MainWindow::showUnderlineButton()
{
QTextCharFormat fmt;
fmt.setFontUnderline(underlineBtn->isChecked());
ui->textEdit->mergeCurrentCharFormat(fmt);
qDebug()<<"underline!!!";
}
void MainWindow::ShowColorBtn()
{
QColor color = QColorDialog::getColor(Qt::red,this);
if(color.isValid()){
QTextCharFormat fmt;
fmt.setForeground(color);
ui->textEdit->mergeCurrentCharFormat(fmt);
}