/** Returns size of the string based on the font used. */ sf::Vector2i Menu::measureString(std::string text, HFONT font) { std::wstring stemp = stringToWideString(text); // Convert 1 byte chars to 2 byte chars LPCWSTR lwtext = stemp.c_str(); // Convert to long pointer to wide string SIZE size; // Size structure to store returned size of the string SelectObject(hdc, font); // Select font // Call function that will give us the size of the text GetTextExtentPoint32(hdc, lwtext, text.size(), &size); // Disect and return string size as the sf::Vector2i return sf::Vector2i(size.cx, size.cy); }
/*! Constructs a new about box on top of given \a parent window. */ AboutBox::AboutBox(QWidget * parent) : QDialog(parent) { setWindowTitle("About MaxCalc"); tstring labelText = _T("MaxCalc v"); labelText += Constants::VERSION; labelText += _T(" ("); labelText += _T("built: "); tstring date = stringToWideString(__DATE__); labelText += date; labelText += _T(")<br>"); labelText += Constants::COPYRIGHT; labelText += _T("<br><a href='"); labelText += Constants::WEBSITE; labelText += _T("'>"); labelText += Constants::WEBSITE; labelText += _T("</a>"); QTextBrowser * label = new QTextBrowser; label->setHtml(QString::fromWCharArray(labelText.c_str())); label->setOpenExternalLinks(true); label->setFrameStyle(QFrame::NoFrame); QPalette p; p.setColor(QPalette::Base, p.color(QPalette::Background)); label->setPalette(p); label->setLineWrapMode(QTextEdit::NoWrap); label->document()->adjustSize(); label->setMinimumSize(label->document()->size().toSize()); label->setMaximumSize(label->document()->size().toSize()); QPushButton * closeButton = new QPushButton; closeButton->setText(tr("&Close")); QGridLayout * layout = new QGridLayout; layout->addWidget(label, 1, 0, 1, -1); layout->addItem(new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed), 2, 1, 1, 1); layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding), 3, 0, 1, 1); layout->addWidget(closeButton, 3, 1, 1, 1); layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding), 3, 2, 1, 1); setLayout(layout); setMaximumSize(sizeHint()); setMinimumSize(sizeHint()); connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); }