NodeSize getNodeSize(QFont font, QFont titlefont, FlowNode& node) { NodeSize ns; QFontMetrics fmetrics(font); QFontMetrics ftmetrics(titlefont); QRect titlebounding = ftmetrics.boundingRect(QString(node.Title.c_str())); int MaxWidth; if (titlebounding.width() < MaxBlockWidth) MaxWidth = MaxBlockWidth; else MaxWidth = titlebounding.width(); QRect descbounding = fmetrics.boundingRect(QRect(0, 0, MaxWidth, 0), Qt::AlignHCenter | Qt::TextWordWrap, QString(node.Desc.c_str())); int blockwidth = BlockPadding*2; if (titlebounding.width() < descbounding.width()) blockwidth += descbounding.width(); else blockwidth += titlebounding.width(); int blockheight = BlockPadding + titlebounding.height() + BlockPadding + descbounding.height() + BlockPadding; ns.DescBoundBox = descbounding; ns.TitleBoundBox = titlebounding; ns.Width = blockwidth; ns.Height = blockheight; return ns; }
CFontListWindow::CFontListWindow(CMainWindow *parent) :QWidget() /* -------------------------------------------------------------------------------------------- DESCRIPTION: Font list window constructor -------------------------------------------------------------------------------------------- PARAMETERS: parent: The parent widget -------------------------------------------------------------------------------------------- RETURNS: none -------------------------------------------------------------------------------------------- */ { //create table widgets for the lists of available-fonts and incompatible-fonts m_tableGoodFonts=new QTableWidget(0,3,this); m_tableBadFonts=new QTableWidget(0,1,this); QStringList headers; headers= (QStringList() << "Name" << "Code Pages" << "File"); m_tableGoodFonts->setHorizontalHeaderLabels(headers); headers.clear(); headers= (QStringList() << " "); m_tableBadFonts->setHorizontalHeaderLabels(headers); //column width is controlled by horizontal headers - set to stretch filling available space m_tableGoodFonts->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); m_tableGoodFonts->horizontalHeader()->setStretchLastSection(true); m_tableBadFonts->horizontalHeader()->setStretchLastSection(true); m_tableGoodFonts->verticalHeader()->hide(); m_tableBadFonts->verticalHeader()->hide(); m_tableBadFonts->horizontalHeader()->hide(); m_tableGoodFonts->setColumnWidth(0,width()/3); m_tableGoodFonts->setColumnWidth(1,width()/3); m_btnClose=new QPushButton(tr("&Close")); connect(m_btnClose,SIGNAL(clicked()),this,SLOT(close())); m_btnHelp= new QPushButton(tr("&Help")); connect(m_btnHelp,SIGNAL(clicked()),this,SLOT(displayHelp())); //buttons can only have one shortcut, and as the Help and Close buttons have the ALT+H and //ALT+C already assigned to them, instead connect the platform specific help key (F1) and //the the Esc key directly to the displayHelp and Close slots QShortcut *helpShortcut=new QShortcut(QKeySequence::HelpContents,this); connect(helpShortcut,SIGNAL(activated()),this,SLOT(displayHelp())); QShortcut *closeShortcut=new QShortcut(QKeySequence(tr("Esc")),this); connect(closeShortcut,SIGNAL(activated()),this,SLOT(close())); //parent window is signalled to actually display the help connect(this,SIGNAL(displayHelpSignal(QString)),parent,SLOT(displayHelp(QString))); m_lblGoodFonts=new QLabel("<b>The list of fonts that are compatible with AlbumEasy:</b>",this); m_lblBadFonts=new QLabel("<b>These fonts are incompatible with AlbumEasy:</b>",this); QHBoxLayout *buttonLayout=new QHBoxLayout; //horizontal layout that contains the close button buttonLayout->addStretch(); buttonLayout->addWidget(m_btnHelp); buttonLayout->addWidget(m_btnClose); QFontMetrics fmetrics(m_tableBadFonts->font()); //restrict the height of the bad font table int h=fmetrics.height(); m_tableBadFonts->setMaximumHeight(6*h); QVBoxLayout *mainLayout=new QVBoxLayout; mainLayout->addWidget(m_lblGoodFonts); mainLayout->addWidget(m_tableGoodFonts,1); //the good font table is set to stretch vertically mainLayout->addWidget(m_lblBadFonts); mainLayout->addWidget(m_tableBadFonts); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); }