Skip to content

Commit

Permalink
Refine tool buttons of main window,.Font by fontawesome.io
Browse files Browse the repository at this point in the history
Font Awesome gives you scalable vector icons that can instantly be customized — size, color, drop shadow, and anything that can be done with the power of CSS.
  • Loading branch information
YanGuam committed Jul 31, 2014
1 parent 9fa4e5c commit fc49c9c
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 56 deletions.
2 changes: 2 additions & 0 deletions QSanguosha.pro
Expand Up @@ -101,6 +101,7 @@ SOURCES += \
src/ui/ChooseTriggerOrderBox.cpp \
src/ui/GraphicsBox.cpp \
src/ui/GuanxingBox.cpp \
src/ui/IconHelper.cpp \
src/util/detector.cpp \
src/util/nativesocket.cpp \
src/util/recorder.cpp \
Expand Down Expand Up @@ -203,6 +204,7 @@ HEADERS += \
src/ui/ChooseTriggerOrderBox.h \
src/ui/GraphicsBox.h \
src/ui/GuanxingBox.h \
src/ui/IconHelper.h \
src/util/detector.h \
src/util/nativesocket.h \
src/util/recorder.h \
Expand Down
Binary file added font/fontawesome-webfont.ttf
Binary file not shown.
100 changes: 49 additions & 51 deletions src/dialog/mainwindow.cpp
Expand Up @@ -33,6 +33,7 @@
#include "UpdateChecker.h"
#include "recorder.h"
#include "audio.h"
#include "IconHelper.h"

#include <lua.hpp>
#include <QGraphicsView>
Expand All @@ -57,7 +58,6 @@
#include <QNetworkReply>
#include <QBitmap>


#if !defined(QT_NO_OPENGL) && defined(USING_OPENGL)
#include <QtOpenGL/QGLWidget>
#endif
Expand Down Expand Up @@ -241,20 +241,30 @@ MainWindow::MainWindow(QWidget *parent)
addAction(ui->actionShow_Hide_Menu);
addAction(ui->actionFullscreen);

minButton = new QToolButton(this);
maxButton = new QToolButton(this);
normalButton = new QToolButton(this);
closeButton= new QToolButton(this);

QPixmap minPix = style()->standardPixmap(QStyle::SP_TitleBarMinButton);
QPixmap maxPix = style()->standardPixmap(QStyle::SP_TitleBarMaxButton);
QPixmap normalPix = style()->standardPixmap(QStyle::SP_TitleBarNormalButton);
QPixmap closePix = style()->standardPixmap(QStyle::SP_TitleBarCloseButton);

minButton->setIcon(minPix);
maxButton->setIcon(maxPix);
normalButton->setIcon(normalPix);
closeButton->setIcon(closePix);
minButton = new QPushButton(this);
minButton->setProperty("control", true);

maxButton = new QPushButton(this);
maxButton->setProperty("bold", true);
maxButton->setProperty("control", true);

normalButton = new QPushButton(this);
normalButton->setProperty("bold", true);
normalButton->setProperty("control", true);

closeButton= new QPushButton(this);
closeButton->setObjectName("closeButton");
closeButton->setProperty("control", true);

menu = new QPushButton(this);
menu->setMenu(ui->menuSumMenu);
menu->setProperty("control", true);

IconHelper::getInstance()->setIcon(minButton, QChar(0xf068), 15);
IconHelper::getInstance()->setIcon(maxButton, QChar(0xf106), 15);
IconHelper::getInstance()->setIcon(normalButton, QChar(0xf107), 15);
IconHelper::getInstance()->setIcon(closeButton, QChar(0xf00d), 15);
IconHelper::getInstance()->setIcon(menu, QChar(0xf0c9), 15);

minButton->setToolTip(tr("<font color=%1>Minimize</font>").arg(Config.SkillDescriptionInToolTipColor.name()));
connect(minButton, SIGNAL(clicked()), this, SLOT(showMinimized()));
Expand All @@ -264,22 +274,10 @@ MainWindow::MainWindow(QWidget *parent)
connect(normalButton, SIGNAL(clicked()), this, SLOT(showNormal()));
closeButton->setToolTip(tr("<font color=%1>Close</font>").arg(Config.SkillDescriptionInToolTipColor.name()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));

const QString styleSheet = "background-color:transparent;";

minButton->setStyleSheet(styleSheet);
maxButton->setStyleSheet(styleSheet);
normalButton->setStyleSheet(styleSheet);
closeButton->setStyleSheet(styleSheet);
menu->setToolTip(tr("<font color=%1>Config</font>").arg(Config.SkillDescriptionInToolTipColor.name()));

menuBar()->hide();

menu = new QPushButton(this);
menu->setMenu(ui->menuSumMenu);
menu->setIcon(QPixmap("image/system/button/config.png"));
menu->setStyleSheet("background-color:transparent; QPushButton::menu-indicator{image:None;}");
menu->setToolTip(tr("<font color=%1>Config</font>").arg(Config.SkillDescriptionInToolTipColor.name()));

ui->menuSumMenu->setStyleSheet("color: black;"
"background-color: white;"
"selection-color: white;"
Expand Down Expand Up @@ -332,7 +330,7 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if (windowState() & Qt::WindowMaximized)
return;
QPoint gloPoint = event->globalPos();
QPoint globalPoint = event->globalPos();
if (isZoomReady && isLeftPressDown) {
QRect rect = this->rect();
QPoint topLeft = mapToGlobal(rect.topLeft());
Expand All @@ -342,44 +340,44 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)

switch (direction) {
case Left:
if (bottomRight.x() - gloPoint.x() <= minimumWidth())
if (bottomRight.x() - globalPoint.x() <= minimumWidth())
rMove.setX(topLeft.x());
else
rMove.setX(gloPoint.x());
rMove.setX(globalPoint.x());
break;
case Right:
rMove.setWidth(gloPoint.x() - topLeft.x());
rMove.setWidth(globalPoint.x() - topLeft.x());
break;
case Up:
if (bottomRight.y() - gloPoint.y() <= minimumHeight())
if (bottomRight.y() - globalPoint.y() <= minimumHeight())
rMove.setY(topLeft.y());
else
rMove.setY(gloPoint.y());
rMove.setY(globalPoint.y());
break;
case Down:
rMove.setHeight(gloPoint.y() - topLeft.y());
rMove.setHeight(globalPoint.y() - topLeft.y());
break;
case LeftTop:
if (bottomRight.x() - gloPoint.x() <= minimumWidth())
if (bottomRight.x() - globalPoint.x() <= minimumWidth())
rMove.setX(topLeft.x());
else
rMove.setX(gloPoint.x());
if (bottomRight.y() - gloPoint.y() <= minimumHeight())
rMove.setX(globalPoint.x());
if (bottomRight.y() - globalPoint.y() <= minimumHeight())
rMove.setY(topLeft.y());
else
rMove.setY(gloPoint.y());
rMove.setY(globalPoint.y());
break;
case RightTop:
rMove.setWidth(gloPoint.x() - topLeft.x());
rMove.setY(gloPoint.y());
rMove.setWidth(globalPoint.x() - topLeft.x());
rMove.setY(globalPoint.y());
break;
case LeftBottom:
rMove.setX(gloPoint.x());
rMove.setHeight(gloPoint.y() - topLeft.y());
rMove.setX(globalPoint.x());
rMove.setHeight(globalPoint.y() - topLeft.y());
break;
case RightBottom:
rMove.setWidth(gloPoint.x() - topLeft.x());
rMove.setHeight(gloPoint.y() - topLeft.y());
rMove.setWidth(globalPoint.x() - topLeft.x());
rMove.setHeight(globalPoint.y() - topLeft.y());
break;
default:
break;
Expand All @@ -389,7 +387,7 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event)
move(event->globalPos() - movePosition);
event->accept();
} else if (!isLeftPressDown)
region(gloPoint);
region(globalPoint);
}

void MainWindow::mouseReleaseEvent(QMouseEvent *)
Expand Down Expand Up @@ -540,11 +538,11 @@ void MainWindow::repaintButtons()
if (!minButton || !maxButton || !normalButton || !closeButton || !menu)
return;
int width = this->width();
minButton->setGeometry(width - 70, 5, 20, 20);
maxButton->setGeometry(width - 49, 5, 20, 20);
normalButton->setGeometry(width - 49, 5, 20, 20);
closeButton->setGeometry(width - 28, 5, 20, 20);
menu->setGeometry(width - 91, 5, 20, 20);
minButton->setGeometry(width - 120, 0, 40, 33);
maxButton->setGeometry(width - 80, 0, 40, 33);
normalButton->setGeometry(width - 80, 0, 40, 33);
closeButton->setGeometry(width - 40, 0, 40, 33);
menu->setGeometry(width - 160, 0, 40, 33);

bool max = windowState() & Qt::WindowMaximized;
if (max) {
Expand Down
9 changes: 4 additions & 5 deletions src/dialog/mainwindow.h
Expand Up @@ -41,7 +41,6 @@ class QGraphicsScene;
class QSystemTrayIcon;
class Server;
class QTextEdit;
class QToolButton;
class QGroupBox;
class RoomItem;
class QNetworkReply;
Expand Down Expand Up @@ -115,10 +114,10 @@ class MainWindow : public QMainWindow {
Window *about_window;
UpdateInfoStruct updateInfomation;

QToolButton *minButton;
QToolButton *maxButton;
QToolButton *normalButton;
QToolButton *closeButton;
QPushButton *minButton;
QPushButton *maxButton;
QPushButton *normalButton;
QPushButton *closeButton;
QPushButton *menu;

QNetworkReply *versionInfomationReply;
Expand Down
42 changes: 42 additions & 0 deletions src/ui/IconHelper.cpp
@@ -0,0 +1,42 @@
/********************************************************************
Copyright (c) 2013-2014 - QSanguosha-Hegemony Team
This file is part of QSanguosha-Hegemony.
This game is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
See the LICENSE file for more details.
QSanguosha-Hegemony Team
*********************************************************************/

#include "IconHelper.h"

#include <QApplication>
#include <QFontDatabase>
#include <QPushButton>

IconHelper *IconHelper::instance = NULL;

IconHelper::IconHelper(QObject *):
QObject(qApp)
{
int fontId = QFontDatabase::addApplicationFont("font/fontawesome-webfont.ttf");
QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0);
iconFont = QFont(fontName);
}

void IconHelper::setIcon(QPushButton* button, QChar iconId, int size)
{
iconFont.setPointSize(size);
button->setFont(iconFont);
button->setText(iconId);
}
53 changes: 53 additions & 0 deletions src/ui/IconHelper.h
@@ -0,0 +1,53 @@
/********************************************************************
Copyright (c) 2013-2014 - QSanguosha-Hegemony Team
This file is part of QSanguosha-Hegemony.
This game is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
See the LICENSE file for more details.
QSanguosha-Hegemony Team
*********************************************************************/

#ifndef ICONHELPER_H
#define ICONHELPER_H

#include <QObject>
#include <QMutex>
#include <QFont>

class QPushButton;

class IconHelper : public QObject
{
private:
explicit IconHelper(QObject *parent = 0);
QFont iconFont;
static IconHelper *instance;

public:
static IconHelper *getInstance()
{
static QMutex mutex;
if (!instance) {
QMutexLocker locker(&mutex);
if (!instance) {
instance = new IconHelper;
}
}
return instance;
}

void setIcon(QPushButton *button, QChar iconId, int size = 10);
};

#endif // ICONHELPER_H
18 changes: 18 additions & 0 deletions style-sheet/sanguosha.qss
Expand Up @@ -96,4 +96,22 @@ QPushButton#speed-up{

QPushButton#uniform{
background-image: url(image/system/button/uniform.png);
}

#MainWindow .QPushButton[control = true]{
color: rgb(183, 218, 238);
background-color:rgba(0,0,0,0);
border-style:none;
}

#MainWindow .QPushButton[control = true]:hover{
background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgba(25, 134, 199, 0), stop:1 rgba(72, 160, 212, 255));
}

#MainWindow .QPushButton[control = true][bold = true]{
font: bold;
}

#MainWindow #closeButton[control = true]:hover{
background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgba(238, 0, 0, 128), stop:1 rgba(238, 44, 44, 255));
}

0 comments on commit fc49c9c

Please sign in to comment.