ContractForm::ContractForm(QString id, QWidget *parent, bool onlyForRead) :
    QDialog(parent)
{
    indexTemp = id;
    QFile file(":/ToolButtonStyle.txt");
    file.open(QFile::ReadOnly);
    QString styleSheetString = QLatin1String(file.readAll());

    labelNumber = new QLabel(trUtf8("Number:"));
    editNumber = new LineEdit;
    editNumber->setReadOnly(onlyForRead);
    labelNumber->setBuddy(editNumber);

    labelDate = new QLabel(trUtf8("Date:"));
    editDate = new QDateEdit;
    editDate->setCalendarPopup(true);
    editDate->setReadOnly(onlyForRead);
    editDate->setDate(QDate::currentDate());

    labelEmployee = new QLabel(trUtf8("FIO:"));
    editEmployee = new LineEdit;
    editEmployee->setReadOnly(onlyForRead);
    labelEmployee->setBuddy(editEmployee);

    QSqlQueryModel *employeeModel = new QSqlQueryModel;
    employeeModel->setQuery("SELECT employeename FROM employee");
    QCompleter *employeeCompleter = new QCompleter(employeeModel);
    employeeCompleter->setCompletionMode(QCompleter::PopupCompletion);
    employeeCompleter->setCaseSensitivity(Qt::CaseSensitive);
    editEmployee->setCompleter(employeeCompleter);

    QToolButton *addButton = new QToolButton;
    QPixmap addPix(":/add.png");
    addButton->setIcon(addPix);
    addButton->setToolTip(trUtf8("Add new record"));
    connect(addButton,SIGNAL(clicked()),this,SLOT(addRecord()));
    addButton->setStyleSheet(styleSheetString);

    QToolButton *seeButton = new QToolButton;
    QPixmap seePix(":/see.png");
    seeButton->setIcon(seePix);
    seeButton->setToolTip(trUtf8("See select item"));
    connect(seeButton,SIGNAL(clicked()),this,SLOT(seeRecord()));
    seeButton->setStyleSheet(styleSheetString);

    QToolButton *listButton = new QToolButton;
    QPixmap listPix(":/list.png");
    listButton->setIcon(listPix);
    listButton->setToolTip(trUtf8("See list of item"));
    connect(listButton,SIGNAL(clicked()),this,SLOT(listRecord()));
    listButton->setStyleSheet(styleSheetString);

    QHBoxLayout *editLayout = new QHBoxLayout;
    editLayout->addWidget(labelEmployee);
    editLayout->addWidget(editEmployee);
    if(!onlyForRead){
        editLayout->addWidget(addButton);
        editLayout->addWidget(seeButton);
        editLayout->addWidget(listButton);
    }

    savePushButton = new QPushButton(trUtf8("Save"));
    connect(savePushButton,SIGNAL(clicked()),this,SLOT(editRecord()));
    savePushButton->setToolTip(trUtf8("Save And Close Button"));

    cancelPushButton = new QPushButton(trUtf8("Cancel"));
    cancelPushButton->setDefault(true);
    cancelPushButton->setStyleSheet("QPushButton:hover {color: red}");
    connect(cancelPushButton,SIGNAL(clicked()),this,SLOT(accept()));
    cancelPushButton->setToolTip(trUtf8("Cancel Button"));

    printPushButton = new QPushButton(trUtf8("Print"));
    //connect(savePushButton,SIGNAL(clicked()),this,SLOT(editRecord()));
    printPushButton->setToolTip(trUtf8("Print Contract Button"));

    buttonBox = new QDialogButtonBox;
    buttonBox->addButton(printPushButton,QDialogButtonBox::ActionRole);
    buttonBox->addButton(cancelPushButton,QDialogButtonBox::ActionRole);
    buttonBox->addButton(savePushButton,QDialogButtonBox::ActionRole);

    if(indexTemp != ""){
        QSqlQuery query;
        query.prepare("SELECT organizationname FROM organization WHERE organizationid = ?");
        query.addBindValue(indexTemp);
        query.exec();
        while(query.next()){
            //editOrganization->setText(query.value(0).toString());
        }
    }else{
        //editOrganization->clear();
    }

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(labelNumber,0,0);
    mainLayout->addWidget(editNumber,0,1);
    mainLayout->addWidget(labelDate,0,2);
    mainLayout->addWidget(editDate,0,3);
    mainLayout->addLayout(editLayout,1,0,1,3);
    if(!onlyForRead){
        mainLayout->addWidget(buttonBox,2,3);
        //editOrganization->selectAll();
    }

    setLayout(mainLayout);

    setWindowTitle(trUtf8("Organization"));
}
示例#2
0
void Receiver::createWidget()
{
    this->setMinimumHeight(150);
    this->setMinimumWidth(500);
    setAutoFillBackground(true);
    QPalette pa = palette();
    pa.setColor(QPalette::Background,QColor(255, 255, 255));

    this->setPalette(pa);
#ifndef Q_OS_MAC
    setStyleSheet("QLineEdit{border: 2px groove rgb(211, 211, 211)} QDoubleSpinBox{border: 2px groove rgb(211, 211, 211);} QComboBox{border: 2px groove rgb(211, 211, 211);}");
#endif

    payTo->setToolTip(tr("输入地址"));
    payTo->setMinimumHeight(25);
    payTo->setMinimumWidth(370);

    QPixmap closePix(":icons/closesend");
    closeButton = new YbLabelButton(closePix);
    QHBoxLayout *closeLayout = new QHBoxLayout;
    closeLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
    closeLayout->addWidget(closeButton);
//    closeLayout->addSpacing(1);
    connect(closeButton, SIGNAL(labelButtonClicked()), this, SIGNAL(closeReceiver()));

    QPixmap addPix(":icons/addsend");
    addButton = new YbLabelButton(addPix);
    QHBoxLayout *addLayout = new QHBoxLayout;
    addLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
    addLayout->addWidget(addButton);
    addLayout->addSpacing(10);
    connect(addButton, SIGNAL(labelButtonClicked()), this, SIGNAL(addReceiver()));

    QLabel *receiverLabel = new QLabel(tr("receiver:"));

    QHBoxLayout *payToLayout = new QHBoxLayout;
    payToLayout->addSpacing(20);
    payToLayout->addWidget(receiverLabel);
    //payToLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
    payToLayout->addWidget(payTo);
    payToLayout->addSpacing(33);

    payAmount->setMinimumHeight(25);
    payAmount->setMinimumWidth(370);
    QHBoxLayout *moneyLayout = new QHBoxLayout;
    //moneyLayout->addSpacing();
    QLabel *moneyText = new QLabel(tr("money:"));
    moneyLayout->addSpacing(20);
    moneyLayout->addWidget(moneyText);
    moneyLayout->addSpacing(12);
    moneyLayout->addWidget(payAmount);
    moneyLayout->addSpacing(40);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(closeLayout);
    mainLayout->addLayout(payToLayout);
    mainLayout->addSpacing(20);
    mainLayout->addLayout(moneyLayout);
    mainLayout->addSpacing(10);
    mainLayout->addLayout(addLayout);
    mainLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));

    setLayout(mainLayout);
}
示例#3
0
RecSkinWidget::RecSkinWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::RecSkinWidget)
    , nowPixNum(-1)
    , m_rowMaxPix(15)
{
    ui->setupUi(this);
    setFixedSize(490,255);

    QStringList l = MOption::instance()->option(OPTION_Recommand, OPTION_GROUP_Theme).toStringList();
    QString appPath = QCoreApplication::applicationDirPath() + "/";

    for(int i = 0; i < 4; ++i)
    {
        RecSkinPushButton *SkinPushButton = new RecSkinPushButton(this);
        connect(SkinPushButton,SIGNAL(currentPixmap(QString,QPixmap,QColor)),
                this,SIGNAL(currentPixmap(QString,QPixmap,QColor)));

        connect(SkinPushButton,SIGNAL(clickNum(int)),
                this,SLOT(onClickNum(int)));
        if(i <= l.size() - 1)
        {
            QString path = appPath + l.at(i);
            qDebug() << path;
            QPixmap pix(path);
            SkinPushButton->setToolTip("");
            if(i == 0)
            {
                QString themeType = MOption::instance()->option("WindowBGPixmapType", "theme").toString();


                QImage skinImage(pix.toImage());
                int num = 0;
                int red = 0;
                int green = 0;
                int blue = 0;
                for(int ii = 0; ii < skinImage.width(); ++ii)
                {
                    for(int j = 0; j < skinImage.height(); ++j)
                    {
                        ++num;
                        QRgb rgbValue(skinImage.pixel(ii, j));
                        red += qRed(rgbValue);
                        green += qGreen(rgbValue);
                        blue += qBlue(rgbValue);
                    }
                }
                if(num != 0)
                {
                    red = red/num;
                    green = green/num;
                    blue = blue/num;
                }

                oneFileName = path;
                onePix = pix;
                oneColor = QColor(red,green,blue,255);
                if(themeType.isEmpty())
                {
                    SkinPushButton->setPixmap(path,pix,oneColor,120,true);

                    QTimer::singleShot(1000, this, SLOT(getRgb()));
                }
                else
                {
                    SkinPushButton->setPixmap(path,pix,QColor(255,255,255,255),120);
                }
            }
            else
            {
                SkinPushButton->setPixmap(path,pix,QColor(255,255,255,255),120);
            }
            SkinPushButton->setSkin(true);
        }


        ui->horizontalLayoutDefault->addWidget(SkinPushButton);
    }

    QPixmap addPix(":/add.png");
    QPixmap historyPix(":/skinHistoryImage.png");
    RecSkinPushButton *button = new RecSkinPushButton(this);
    button->setPixmap("",addPix, QColor(255,255,255,255),60,false);
    connect(button,SIGNAL(clickResult()),
            this,SIGNAL(definePixmapResult()));
    ui->horizontalLayoutHistoryBotton->insertWidget(0,button);


    QString historyPath = QCoreApplication::applicationDirPath() + "/theme/saved";

    // TODO MEM leak
    QDir *dir = new QDir(historyPath);
    QStringList filter;

    QList<QFileInfo> *fileInfo=new QList<QFileInfo>(dir->entryInfoList(filter));

    QStringList fileNames;

    for(int i = 0; i < fileInfo->count(); ++ i)
    {
        if(fileInfo->at(i).isDir())
            continue;
        fileNames << fileInfo->at(i).fileName();
    }
    fileNames.sort();
    int fileSize = fileNames.size();
    if(fileSize > m_rowMaxPix)
        fileSize = m_rowMaxPix;

    for(int i = 0; i < m_rowMaxPix - fileSize; ++i)
    {
        addItem("",historyPix, QColor(255,255,255,255),false,false);
    }

    for(int i = 0; i < fileSize; ++i)
    {
        QString imagePathName = historyPath + "/" + fileNames.value(i);
        QPixmap pxi(imagePathName);
        addItem(imagePathName,pxi, QColor(255,255,255,255),false,true);
    }

    QString themeType = MOption::instance()->option("WindowBGPixmapType", "theme").toString();
    if(themeType == "bitmap")
    {
        QString fileName = MOption::instance()->option("WindowBGPixmap", "theme").toString();

        for(int i = 0; i < buttons.size(); ++i)
        {
            if(buttons.value(i)->getFileName() == fileName)
                nowPixNum = i;
        }
    }
}