Make buttons border have different colors when mouse is over or it is pressed
authorunc0rr
Tue, 05 Aug 2008 20:57:08 +0000
changeset 1152 c72b939c00df
parent 1151 ee6573db301a
child 1153 825931b81ad4
Make buttons border have different colors when mouse is over or it is pressed
QTfrontend/main.cpp
QTfrontend/pages.cpp
QTfrontend/pages.h
QTfrontend/res/Exit.png
QTfrontend/res/LocalPlay.png
QTfrontend/res/NetworkPlay.png
--- a/QTfrontend/main.cpp	Tue Aug 05 15:39:51 2008 +0000
+++ b/QTfrontend/main.cpp	Tue Aug 05 20:57:08 2008 +0000
@@ -54,19 +54,28 @@
 	Q_INIT_RESOURCE(hedgewars);
 
 	qApp->setStyleSheet
-	  (QString(
-		   ".HWForm{"
-		   "background-image: url(\":/res/Background.png\");"
-		   "background-position: bottom center;"
-		   //" background-origin: content;"
-		   "background-repeat: repeat-x;"
-		   "background-color: #870c8f;"
-		   "}"
-		   "PageMain > QPushButton{"
-		   "border: solid transparent;"
-		   "}"
-		   )
-	   );
+		(QString(
+				".HWForm{"
+				"background-image: url(\":/res/Background.png\");"
+				"background-position: bottom center;"
+				"background-repeat: repeat-x;"
+				"background-color: #870c8f;"
+				"}"
+				"PageMain > QPushButton{"
+				"border: solid;"
+				"border-width: 4px;"
+				"border-radius: 8px;"
+				"border-color: orange;"
+				"background-origin: content;"
+				"}"
+				"PageMain > QPushButton:hover{"
+				"border-color: yellow;"
+				"}"
+				"PageMain > QPushButton:pressed{"
+				"border-color: white;"
+				"}"
+			)
+		);
 
 	bindir->cd("bin"); // workaround over NSIS installer
 
--- a/QTfrontend/pages.cpp	Tue Aug 05 15:39:51 2008 +0000
+++ b/QTfrontend/pages.cpp	Tue Aug 05 20:57:08 2008 +0000
@@ -60,25 +60,25 @@
 	//pageLayout->setColumnStretch(1, 2);
 	//pageLayout->setColumnStretch(2, 1);
 
-	QPushButton* btnLogo = addButton(":/res/HedgewarsTitle.png", pageLayout, 0, 0, 1, 4, QSize(720, 140));
+	QPushButton* btnLogo = addButton(":/res/HedgewarsTitle.png", pageLayout, 0, 0, 1, 4, true);
 	pageLayout->setAlignment(btnLogo, Qt::AlignHCenter);
 	pageLayout->setRowStretch(0, 1);
 	pageLayout->setRowStretch(1, 1);
 	pageLayout->setRowStretch(2, 0);
 	pageLayout->setRowStretch(3, 1);
 
-	BtnSinglePlayer = addButton(":/res/LocalPlay.png", pageLayout, 2, 0, 1, 2, QSize(314, 260));
+	BtnSinglePlayer = addButton(":/res/LocalPlay.png", pageLayout, 2, 0, 1, 2, true);
 	pageLayout->setAlignment(BtnSinglePlayer, Qt::AlignHCenter);
 
-	BtnNet = addButton(":/res/NetworkPlay.png", pageLayout, 2, 2, 1, 2, QSize(314, 260));
+	BtnNet = addButton(":/res/NetworkPlay.png", pageLayout, 2, 2, 1, 2, true);
 	pageLayout->setAlignment(BtnNet, Qt::AlignHCenter);
 
-	BtnSetup = addButton(":/res/Settings.png", pageLayout, 3, 3, QSize(54, 50));
+	BtnSetup = addButton(":/res/Settings.png", pageLayout, 3, 3, true);
 
-	BtnInfo = addButton(":/res/About.png", pageLayout, 3, 1, 1, 2, QSize(116, 37));
+	BtnInfo = addButton(":/res/About.png", pageLayout, 3, 1, 1, 2, true);
 	pageLayout->setAlignment(BtnInfo, Qt::AlignHCenter);
 
-	BtnExit = addButton(":/res/Exit.png", pageLayout, 3, 0, 1, 1, QSize(58, 52));
+	BtnExit = addButton(":/res/Exit.png", pageLayout, 3, 0, 1, 1, true);
 }
 
 PageEditTeam::PageEditTeam(QWidget* parent) :
--- a/QTfrontend/pages.h	Tue Aug 05 15:39:51 2008 +0000
+++ b/QTfrontend/pages.h	Tue Aug 05 20:57:08 2008 +0000
@@ -59,15 +59,16 @@
   }
   virtual ~AbstractPage() {};
 
-  QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, const QSize sz=QSize(0, 0)) {
+  QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, bool iconed = false) {
     QPushButton* butt = new QPushButton(this);
-    if (sz==QSize(0, 0)) {
+    if (!iconed) {
       butt->setFont(*font14);
       butt->setText(btname);
     } else {
       const QIcon& lp=QIcon(btname);
+      QSize sz = lp.actualSize(QSize(65535, 65535));
       butt->setIcon(lp);
-      butt->setFixedSize(sz+QSize(2, 2));
+      butt->setFixedSize(sz);
       butt->setIconSize(sz);
       butt->setFlat(true);
       butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@@ -76,15 +77,16 @@
     return butt;
   };
 
-  QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, int rowSpan, int columnSpan, const QSize sz=QSize(0, 0)) {
+  QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, int rowSpan, int columnSpan, bool iconed = false) {
     QPushButton* butt = new QPushButton(this);
-    if (sz==QSize(0, 0)) {
+    if (!iconed) {
       butt->setFont(*font14);
       butt->setText(btname);
     } else {
       const QIcon& lp=QIcon(btname);
+      QSize sz = lp.actualSize(QSize(65535, 65535));
       butt->setIcon(lp);
-      butt->setFixedSize(sz+QSize(2, 2));
+      butt->setFixedSize(sz);
       butt->setIconSize(sz);
       butt->setFlat(true);
       butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
Binary file QTfrontend/res/Exit.png has changed
Binary file QTfrontend/res/LocalPlay.png has changed
Binary file QTfrontend/res/NetworkPlay.png has changed