/***************************/
immessagebox.cpp
#include
#include
#include "immessagebox.h"
ImMessageBox::ImMessageBox(QWidget *parent)
: QMessageBox(QMessageBox::Warning, "", "", 0, parent, Qt::Sheet)
{
setFixedWidth(200);
QCheckBox dontPrompt("Do not prompt again", this);
QCheckBox dontPrompt2("Do not prompt again8888888", this);
QLineEdit* pEdit = new QLineEdit("Input Text");
QPushButton* pAdd = new QPushButton("add");
QPushButton* pSave = addButton(QMessageBox::Save);
QPushButton* pOK = addButton(QMessageBox::Close);
// 对Label不对换行的改进测试
QString newStr;
QString str("ddddddddd0 ddddddddd1 12233445566778899中期苛啊是的法ccddeef3 fggddddd5 dddd4 ddd5555ddd7 dddddddd8 ddddddd9 ddddq ddddddww");
while(str.length() > 20)
{
QChar c = str.at(20);
bool bLN = c.isLetterOrNumber();
if (!bLN)
{
newStr += str.left(20) + "\n";
str.remove(0, 20) ;
}
else
{
QString tmpStr = str.left(20);
int nPos = tmpStr.lastIndexOf(" ");
nPos = nPos>0?nPos:20;
newStr += str.left(nPos) + "\n";
str.remove(0, nPos) ;
}
}
newStr += str;
QLabel* pLabel = new QLabel(newStr);
pLabel->setWordWrap(true);
pLabel->setIndent(20);
QSpacerItem *pSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
QComboBox* pCombox = new QComboBox();
pCombox->addItem("aaaa");
pCombox->addItem("bbbb");
pCombox->addItem("CCCC");
dynamic_cast< QGridLayout *>(layout())->addWidget(pLabel, 0, 1, 1, 4);
dynamic_cast< QGridLayout *>(layout())->addWidget(&dontPrompt, 2, 1,1,4);
dynamic_cast< QGridLayout *>(layout())->addWidget(&dontPrompt2, 3, 1,1,2);
dynamic_cast< QGridLayout *>(layout())->addWidget(pEdit, 3, 3,1,2);
dynamic_cast< QGridLayout *>(layout())->addWidget(pCombox, 5, 1, 1, 4);
dynamic_cast< QGridLayout *>(layout())->addItem(pSpacer, 8, 1);
dynamic_cast< QGridLayout *>(layout())->addWidget(pAdd, 8, 2);
dynamic_cast< QGridLayout *>(layout())->addWidget(pSave, 8, 3);
dynamic_cast< QGridLayout *>(layout())->addWidget(pOK, 8, 4);
// replace default icon
QPixmap map("bmp.png");
setIconPixmap(map);
}
ImMessageBox::ImMessageBox( const QString & title, const QString & text, QWidget *parent)
: QMessageBox(parent)
{
setWindowTitle(title);
}
ImMessageBox::~ImMessageBox()
{
}
void ImMessageBox::onOpenUrl(const QString &url)
{
bool bRet = QDesktopServices::openUrl(url);
qDebug() << url;
}
void ImMessageBox::addWidgetEx ( QWidget * widget, int row, int column, Qt::Alignment alignment, bool bLink )
{
dynamic_cast< QGridLayout *>(layout())->addWidget(widget, row, column, alignment);
if (bLink)
{
connect(widget, SIGNAL(linkActivated(const QString &)), this, SLOT(onOpenUrl(const QString &)));
}
}
void ImMessageBox::addWidgetExt ( QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment, bool bLink )
{
dynamic_cast< QGridLayout *>(layout())->addWidget(widget, fromRow, fromColumn, rowSpan, columnSpan, alignment);
if (bLink)
{
connect(widget, SIGNAL(linkActivated(const QString &)), this, SLOT(onOpenUrl(const QString &)));
}
}