?? colordialog.cpp
字號:
/****************************************************************************
** $Id: /sample/7/colordialog.cpp 2.3.2 edited 2004-10-12 $
**
** Copyright (C) 2004-2005 OURSELEC AS. All rights reserved.
** http://www.ourselec.com
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "colordialog.h"
ColorDialog::ColorDialog( QWidget *parent, const char *name,
bool isModal)
:QDialog( parent, name, isModal )
{
setCaption( "Qt Colors" );
int width = 90;
int height = 30;
int x = 1;
int y = 1;
col = white;
whiteButton = new QPushButton( "white", this );
whiteButton->setFlat( TRUE );
whiteButton->setBackgroundColor( white );
redButton = new QPushButton( "red", this );
redButton->setFlat( TRUE );
redButton->setBackgroundColor( red );
greenButton = new QPushButton( "green", this );
greenButton->setFlat( TRUE );
greenButton->setBackgroundColor( green );
blueButton = new QPushButton( "blue", this );
blueButton->setFlat( TRUE );
blueButton->setBackgroundColor( blue );
cyanButton = new QPushButton( "cyan", this );
cyanButton->setFlat( "TRUE" );
cyanButton->setBackgroundColor( cyan );
magentaButton = new QPushButton( "magenta", this );
magentaButton->setFlat( TRUE );
magentaButton->setBackgroundColor( magenta );
yellowButton = new QPushButton( "yellow", this );
yellowButton->setFlat( TRUE );
yellowButton->setBackgroundColor( yellow );
grayButton = new QPushButton( "gray", this );
grayButton->setFlat( TRUE );
grayButton->setBackgroundColor( gray );
blackButton = new QPushButton( "black", this );
blackButton->setFlat( TRUE );
blackButton->setBackgroundColor( black );
dredButton = new QPushButton( "darkRed", this );
dredButton->setFlat( TRUE );
dredButton->setBackgroundColor( darkRed );
dgreenButton = new QPushButton( "darkGreen", this );
dgreenButton->setFlat( TRUE );
dgreenButton->setBackgroundColor( darkGreen );
dblueButton = new QPushButton( "darkBlue", this );
dblueButton->setFlat( TRUE );
dblueButton->setBackgroundColor( darkBlue );
dcyanButton = new QPushButton( "darkCyan", this );
dcyanButton->setFlat( "TRUE" );
dcyanButton->setBackgroundColor( darkCyan );
dmagentaButton = new QPushButton( "darkMagenta", this );
dmagentaButton->setFlat( TRUE );
dmagentaButton->setBackgroundColor( darkMagenta );
dyellowButton = new QPushButton( "darkYellow", this );
dyellowButton->setFlat( TRUE );
dyellowButton->setBackgroundColor( darkYellow );
dgrayButton = new QPushButton( "darkGray", this );
dgrayButton->setFlat( TRUE );
dgrayButton->setBackgroundColor( darkGray );
lgrayButton = new QPushButton( "lightGray", this );
lgrayButton->setFlat( TRUE );
lgrayButton->setBackgroundColor( lightGray );
whiteButton->setGeometry( x, y, width, height );
blackButton->setGeometry( ( x+width ), y, width, height);
redButton->setGeometry( x, ( y+height ), width, height );
dredButton->setGeometry( ( x+width ), ( y+height ), width, height );
greenButton->setGeometry( x, ( y+height*2 ), width, height );
dgreenButton->setGeometry( ( x+width ), ( y+height*2 ),
width, height );
blueButton->setGeometry( x, ( y+height*3 ), width, height );
dblueButton->setGeometry( ( x+width ), ( y+height*3 ),
width, height );
cyanButton->setGeometry( x, ( y+height*4 ), width, height );
dcyanButton->setGeometry( (x+width), ( y+height*4 ),
width, height );
magentaButton->setGeometry( x, ( y+height*5 ), width, height );
dmagentaButton->setGeometry( ( x+width ), ( y+height*5 ),
width, height );
yellowButton->setGeometry( x, ( y+height*6 ), width, height );
dyellowButton->setGeometry( ( x+width ), ( y+height*6 ),
width, height );
grayButton->setGeometry( x, ( y+height*7 ), width, height );
dgrayButton->setGeometry( ( x+width ), ( y+height*7 ),
width, height );
lgrayButton->setGeometry( x, ( y+height*8 ), width*2, height );
connect( whiteButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( blackButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( redButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( dredButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( greenButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( dgreenButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( blueButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( dblueButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( cyanButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( dcyanButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( magentaButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( dmagentaButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( yellowButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( dyellowButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( grayButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( dgrayButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
connect( lgrayButton, SIGNAL( pressed() ),
SLOT( chooseColor() ) );
}
void ColorDialog::chooseColor()
{
if ( whiteButton->isDown() ) {
col = white;
} else if ( blackButton->isDown() ) {
col = black;
} else if ( redButton->isDown() ) {
col = red;
} else if ( dredButton->isDown() ) {
col = darkRed;
} else if ( greenButton->isDown() ) {
col = green;
} else if ( dgreenButton->isDown() ) {
col = darkGreen;
} else if ( blueButton->isDown() ) {
col = blue;
} else if ( dblueButton->isDown() ) {
col = darkBlue;
} else if ( cyanButton->isDown() ) {
col = cyan;
} else if ( dcyanButton->isDown() ) {
col = darkCyan;
} else if ( magentaButton->isDown() ) {
col = magenta;
} else if ( dmagentaButton->isDown() ) {
col = darkMagenta;
} else if ( yellowButton->isDown() ) {
col = yellow;
} else if ( dyellowButton->isDown() ) {
col = darkYellow;
} else if ( grayButton->isDown() ) {
col = gray;
} else if ( dgrayButton->isDown() ) {
col = darkGray;
} else if ( lgrayButton->isDown() ) {
col = lightGray;
}
this->close();
}
QColor ColorDialog::color()
{
return col;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -