#include "colorcombobox.h"
#define TABLEROW 7
#define TABLECOLUMN 4
colorcombobox::colorcombobox(QWidget *parent)
:QComboBox(parent)
{
ColorId = 0;
currentRow = 0;
currentColumn = 0;
currentColor = nullptr;
showColor = new QLabel(this);
showColor->setParent(this);
showColor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
tablewidget = new QTableWidget(TABLEROW,TABLECOLUMN);
tablewidget->verticalHeader()->setVisible(false);
tablewidget->horizontalHeader()->setVisible(false);
tablewidget->setShowGrid(false);
tablewidget->setSpan(0,0,1,TABLECOLUMN);
tablewidget->setSpan(TABLEROW-3,0,1,TABLECOLUMN);
tablewidget->setSpan(TABLEROW-2,0,1,TABLECOLUMN);
RepaintList<<"red";
RepaintList<<"yellow";
RepaintList<<"green";
RepaintList<<"aliceblue";
RepaintList<<"antiquewhite";
RepaintList<<"aqua";
RepaintList<<"aquamarine";
RepaintList<<"azure";
RepaintList<<"beige";
RepaintList<<"bisque";
RepaintList<<"blue";
RepaintList<<"brown";
RepaintList<<"burlywood";
RepaintList<<"cadetblue";
RepaintList<<"coral";
RepaintList<<"cornsilk";
int k =0;
for (int i =0;i<TABLEROW;i++) {
if (i==TABLEROW-3)
{
other = new QPushButton(this);
other->setText(tr("other color"));
other->setObjectName("PushButton00");
tablewidget->setCellWidget(TABLEROW-3,0,other);
}
else if(i == TABLEROW-2)
{
labeltext = new QLabel(this);
labeltext->setText(tr("Recently used colors"));
tablewidget->setCellWidget(TABLEROW-2,0,labeltext);
labeltext->setStyleSheet("background-color:white");
}
else if(i == 0)
{
QLabel * labelshow = new QLabel;
labelshow->setText(tr("Standard Color"));
tablewidget->setCellWidget(0,0,labelshow);
labelshow->setStyleSheet("background-color:white");
}
else if(i == TABLEROW-1)
{
btn0 = new MyPushButton;
btn1 = new MyPushButton;
btn2 = new MyPushButton;
btn3 = new MyPushButton;
tablewidget->setCellWidget(i,0,btn0);
tablewidget->setCellWidget(i,1,btn1);
tablewidget->setCellWidget(i,2,btn2);
tablewidget->setCellWidget(i,3,btn3);
connect(btn0,SIGNAL(clicked(QString)),this,SLOT(change(QString)));
connect(btn1,SIGNAL(clicked(QString)),this,SLOT(change(QString)));
connect(btn2,SIGNAL(clicked(QString)),this,SLOT(change(QString)));
connect(btn3,SIGNAL(clicked(QString)),this,SLOT(change(QString)));
}
else
{
for (int j=0;j<TABLECOLUMN;j++) {
tablewidget->setColumnWidth(j,tablewidget->geometry().width()/TABLECOLUMN);
MyPushButton * itemp = new MyPushButton;
itemp->setObjectName("PushButton"+QString::number(i)+QString::number(j));
if(i<TABLEROW)
itemp->setStyleSheet("background-color:"+RepaintList[k]);
k++;
tablewidget->setCellWidget(i,j,itemp);
connect(itemp,SIGNAL(clicked(QString)),this,SLOT(change(QString)));
}
}
}
connect(other,SIGNAL(clicked()),this,SLOT(otherColor()));
this->setModel(tablewidget->model());
this->setView(tablewidget);
}
colorcombobox::~colorcombobox(){
}
void colorcombobox::change(QString colorname)
{
QPushButton * btn = (QPushButton *)sender();
currentRow = btn->objectName().mid(10,1).toInt();
currentColumn = btn->objectName().mid(11,1).toInt();
currentColor = QColor(colorname);
//update btn's color in the last row
//the next get the the last's color
if(btn0->palette().color(QPalette::Background).name()!=colorname&&
btn1->palette().color(QPalette::Background).name()!=colorname&&
btn2->palette().color(QPalette::Background).name()!=colorname&&
btn3->palette().color(QPalette::Background).name()!=colorname)
{
btn3->setStyleSheet("background-color:"+btn2->palette().color(QPalette::Background).name());
btn2->setStyleSheet("background-color:"+btn1->palette().color(QPalette::Background).name());
btn1->setStyleSheet("background-color:"+btn0->palette().color(QPalette::Background).name());
btn0->setStyleSheet("background-color:"+colorname);
}
qDebug()<<"color"<<btn->objectName()<<currentRow<<currentColumn<<currentColor.name();
showColor->setStyleSheet("QLabel{background-color:"+colorname+";}");
}
void colorcombobox::otherColor()
{
qDebug()<<"othercolor";
QColor colorOrg = QColor();
QColor mycolor = QColorDialog::getColor(colorOrg,this);
other->setStyleSheet("background-color:"+mycolor.name());
this->change(mycolor.name());
}
void colorcombobox::sendColor()
{
}
void colorcombobox::setCurrentIndex(int i)
{
//update current params
if(i<RepaintList.size())
setCurrentColor(QColor(RepaintList[i]));
}
void colorcombobox::setCurrentColor(QColor color)
{
//update current params
currentRow = 0;
currentColumn = 0;
currentColor = color;
if(RepaintList.contains(color.name()))
{
currentRow = RepaintList.indexOf(color.name())/4;
currentColumn = RepaintList.indexOf(color.name())%4;
}
else
{
other->setStyleSheet("background-color:"+color.name());
}
showColor->setStyleSheet("QLabel{background-color:"+color.name()+";}");
btn0->setStyleSheet("background-color:"+color.name());
}
void colorcombobox::resizeEvent(QResizeEvent *e)
{
QRect rect = this->geometry();
rect.setX(0);
rect.setY(0);
qDebug()<<rect.width()<<rect.height();
showColor->setGeometry(1,1,rect.width()-2,rect.height()-2);
for (int var = 0; var < TABLECOLUMN; ++var) {
tablewidget->setColumnWidth(var,(rect.width()-10)/(TABLECOLUMN));
}
}
风木菌
- 粉丝: 3
- 资源: 1
最新资源
- 【全年行事历】行政部全年活动计划表- A公司.xls
- 【全年行事历】活动复盘表.xlsx
- 【全年行事历】活动推广进度表.xlsx
- 【全年行事历】旅游团建行程安排表-XX山.xlsx
- 【全年行事历】旅行团建活动方案.pptx
- 【全年行事历】某公司团建活动方案-【户外烧烤】.doc.baiduyun.uploading.cfg
- 【全年行事历】企业文化年度活动计划表.xlsx
- 【全年行事历】年度员工关怀计划表.xlsx
- 【全年行事历】年度行政活动计划表.xlsx
- 【全年行事历】企业团队建设活动策划.pptx
- 【全年行事历】全年活动计划.xls
- 【全年行事历】团队建设企业文化行事历——工作计划.xlsx
- 【全年行事历】企业员工夏季团建活动策划一天.pptx
- 【全年行事历】团建费用分析.xlsx
- 【全年行事历】团建行程安排及出行清单.xlsx
- 【全年行事历】团建活动采购预算清单.xlsx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0