#define CLOGIN_H
#include <QDialog>
#include <QKeyEvent>
namespace Ui {
class CLogin;
}
class CLogin : public QDialog
{
Q_OBJECT
public:
explicit CLogin(QWidget *parent = 0);
~CLogin();
protected:
void keyPressEvent(QKeyEvent *);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private slots:
void on_pushButton_clicked();
void on_minButton_clicked();
void on_closeButton_clicked();
private:
Ui::CLogin *ui;
bool m_MousePressed;
QPoint m_RelativeSrcPos;
};
#endif // CLOGIN_H
#include "clogin.h"
#include "ui_clogin.h"
#include <QDesktopWidget>
CLogin::CLogin(QWidget *parent) :
QDialog(parent),
ui(new Ui::CLogin)
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint);
QDesktopWidget *deskdop = QApplication::desktop();
move((deskdop->width() - this->width())/2, (deskdop->height() - this->height())/2);
m_MousePressed = false;
}
CLogin::~CLogin()
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
delete ui;
}
void CLogin::on_pushButton_clicked()
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
accept();
}
void CLogin::keyPressEvent(QKeyEvent *e)
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
int nKey = e->key();
if(Qt::Key_Return==nKey||Qt::Key_Enter==nKey)
{
}
}
void CLogin::mousePressEvent(QMouseEvent *event)
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
if(event->button() == Qt::LeftButton)
{
m_MousePressed = true;
m_RelativeSrcPos = event->globalPos() - pos();
}
}
void CLogin::mouseReleaseEvent(QMouseEvent *event)
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
m_MousePressed = false;
}
void CLogin::mouseMoveEvent(QMouseEvent *event)
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
if(m_MousePressed)
{
move(event->globalPos() - m_RelativeSrcPos);
}
}
void CLogin::on_minButton_clicked()
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
showMinimized();
}
void CLogin::on_closeButton_clicked()
{
qDebug("%s::%d::%s", __FILE__, __LINE__,__FUNCTION__);
qApp->quit();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "clogin.h"
#include <QTextCodec>
int main(int argc, char *argv[])
{
QTextCodec * sys = QTextCodec::codecForName("System");
QTextCodec::setCodecForCStrings(sys);
QTextCodec::setCodecForLocale(sys);
QTextCodec::setCodecForTr(sys);
QApplication a(argc, argv);
QFile qss("client.qss");
qss.open(QFile::ReadOnly);
a.setStyleSheet(qss.readAll());
MainWindow w;
CLogin m;
if(m.exec() == QDialog::Accepted)
{
w.showMaximized();
w.show();
return a.exec();
}
else
{
return 0;
}
}