| 1 | #include "wmpage.h" | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | WmPage::WmPage(QWidget *currentTab) | 
 
 
 
 
 | 4 | { | 
 
 
 
 
 | 5 | createAndAddPageToTab(currentTab); | 
 
 
 
 
 | 6 | } | 
 
 
 
 
 | 7 |  | 
 
 
 
 
 | 8 | void WmPage::createAndAddPageToTab(QWidget *currentTab){ | 
 
 
 
 
 | 9 | // Adapted from here: http://stackoverflow.com/questions/5258665/how-to-set-number-of-lines-for-an-qtextedit | 
 
 
 
 
 | 10 | // Thanks TonyK | 
 
 
 
 
 | 11 | // Note: not working totally as expected. It isnt resizing correctly for the number of rows. | 
 
 
 
 
 | 12 | std::function<void(QTextEdit*, int)> setNumberOfRows = [](QTextEdit* textEdit, int rows){ | 
 
 
 
 
 | 13 | textEdit->setFixedHeight(QFontMetrics(textEdit->font()).lineSpacing() * rows); | 
 
 
 
 
 | 14 | }; | 
 
 
 
 
 | 15 |  | 
 
 
 
 
 | 16 | this->pageTab = currentTab; | 
 
 
 
 
 | 17 |  | 
 
 
 
 
 | 18 | QGroupBox *mainTextGroupBox = new QGroupBox(this->pageTab); | 
 
 
 
 
 | 19 | mainTextGroupBox->setTitle("Main Text"); | 
 
 
 
 
 | 20 |  | 
 
 
 
 
 | 21 | this->mainText = new QTextEdit(this->pageTab); | 
 
 
 
 
 | 22 | setNumberOfRows(this->mainText, 8); | 
 
 
 
 
 | 23 | this->mainText->setAcceptRichText(false); // block pasting of external formatting | 
 
 
 
 
 | 24 | this->mainText->setWordWrapMode(QTextOption::NoWrap); | 
 
 
 
 
 | 25 | QPalette auxPalette = this->mainText->palette(); | 
 
 
 
 
 | 26 | auxPalette.setColor(QPalette::Base, QColor(64,64,64)); | 
 
 
 
 
 | 27 | this->mainText->setPalette(auxPalette); | 
 
 
 
 
 | 28 |  | 
 
 
 
 
 | 29 | QVBoxLayout *mainTextGroupBoxLayout = new QVBoxLayout(); | 
 
 
 
 
 | 30 | mainTextGroupBoxLayout->addWidget(this->mainText); | 
 
 
 
 
 | 31 | mainTextGroupBox->setLayout(mainTextGroupBoxLayout); | 
 
 
 
 
 | 32 |  | 
 
 
 
 
 | 33 | footerTextGroupBox = new QGroupBox(this->pageTab); | 
 
 
 
 
 | 34 | footerTextGroupBox->setTitle("Footer Text"); | 
 
 
 
 
 | 35 |  | 
 
 
 
 
 | 36 | this->footerText = new QTextEdit(footerTextGroupBox); | 
 
 
 
 
 | 37 | setNumberOfRows(this->footerText, 4); | 
 
 
 
 
 | 38 | this->footerText->setAcceptRichText(false); // block pasting of external formatting | 
 
 
 
 
 | 39 | this->footerText->setWordWrapMode(QTextOption::NoWrap); | 
 
 
 
 
 | 40 | this->footerText->setPalette(auxPalette); | 
 
 
 
 
 | 41 |  | 
 
 
 
 
 | 42 |  | 
 
 
 
 
 | 43 | QVBoxLayout *footerTextGroupBoxLayout = new QVBoxLayout(); | 
 
 
 
 
 | 44 | footerTextGroupBoxLayout->addWidget(this->footerText); | 
 
 
 
 
 | 45 | footerTextGroupBox->setLayout(footerTextGroupBoxLayout); | 
 
 
 
 
 | 46 |  | 
 
 
 
 
 | 47 | this->middleImage = new QLabel(this->pageTab); | 
 
 
 
 
 | 48 | this->middleImage->setText("No image selected"); | 
 
 
 
 
 | 49 | this->middleImage->setFixedSize(140,100); | 
 
 
 
 
 | 50 | this->middleImage->setFrameShape(QFrame::StyledPanel); | 
 
 
 
 
 | 51 | this->middleImage->setWordWrap(true); // allows us to have text in multiple rows | 
 
 
 
 
 | 52 | this->middleImage->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); // align text at center | 
 
 
 
 
 | 53 |  | 
 
 
 
 
 | 54 | this->addRemoveImageButton = new QToolButton(this->pageTab); | 
 
 
 
 
 | 55 | this->addRemoveImageButton->setToolTip("Click to add an image"); | 
 
 
 
 
 | 56 | this->addRemoveImageButton->setIcon(QIcon(":/new/icons/plus.png")); | 
 
 
 
 
 | 57 |  | 
 
 
 
 
 | 58 | QHBoxLayout *imageLayoutCenter = new QHBoxLayout(); | 
 
 
 
 
 | 59 | imageLayoutCenter->addSpacerItem(new QSpacerItem(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed)); | 
 
 
 
 
 | 60 | imageLayoutCenter->addWidget(this->middleImage); | 
 
 
 
 
 | 61 | imageLayoutCenter->addWidget(this->addRemoveImageButton); | 
 
 
 
 
 | 62 | imageLayoutCenter->addSpacerItem(new QSpacerItem(1,1, QSizePolicy::Expanding, QSizePolicy::Fixed)); | 
 
 
 
 
 | 63 |  | 
 
 
 
 
 | 64 | QVBoxLayout *pageLayout = new QVBoxLayout(); | 
 
 
 
 
 | 65 | pageLayout->addWidget(mainTextGroupBox); | 
 
 
 
 
 | 66 | pageLayout->addLayout(imageLayoutCenter); | 
 
 
 
 
 | 67 | pageLayout->addWidget(footerTextGroupBox); | 
 
 
 
 
 | 68 |  | 
 
 
 
 
 | 69 | this->pageTab->setLayout(pageLayout); | 
 
 
 
 
 | 70 |  | 
 
 
 
 
 | 71 | // Connect addRemoveImageButton to our slot | 
 
 
 
 
 | 72 | connect(this->addRemoveImageButton, SIGNAL(clicked(bool)), this, SLOT(addRemoveImageButtonTriggered())); | 
 
 
 
 
 | 73 | } | 
 
 
 
 
 | 74 |  | 
 
 
 
 
 | 75 |  | 
 
 
 
 
 | 76 | QTextEdit& WmPage::getMainText(){ | 
 
 
 
 
 | 77 | return *this->mainText; | 
 
 
 
 
 | 78 | } | 
 
 
 
 
 | 79 |  | 
 
 
 
 
 | 80 | QTextEdit& WmPage::getFooterText(){ | 
 
 
 
 
 | 81 | return *this->footerText; | 
 
 
 
 
 | 82 | } | 
 
 
 
 
 | 83 |  | 
 
 
 
 
 | 84 | QLabel& WmPage::getMiddleImage(){ | 
 
 
 
 
 | 85 | return *this->middleImage; | 
 
 
 
 
 | 86 | } | 
 
 
 
 
 | 87 |  | 
 
 
 
 
 | 88 | void WmPage::hideFooterText(){ | 
 
 
 
 
 | 89 | this->footerTextGroupBox->hide(); | 
 
 
 
 
 | 90 | } | 
 
 
 
 
 | 91 |  | 
 
 
 
 
 | 92 | void WmPage::showFooterText(){ | 
 
 
 
 
 | 93 | this->footerTextGroupBox->show(); | 
 
 
 
 
 | 94 | } | 
 
 
 
 
 | 95 |  | 
 
 
 
 
 | 96 | void WmPage::addRemoveImageButtonTriggered(){ | 
 
 
 
 
 | 97 |  | 
 
 
 
 
 | 98 | if(this->middleImage->pixmap() == nullptr){ | 
 
 
 
 
 | 99 |  | 
 
 
 
 
 | 100 | QString selectedImage = QFileDialog::getOpenFileName(this->pageTab,"Choose the image file...","./" , "Image (*.JPG *.JPEG *.PNG)"); | 
 
 
 
 
 | 101 |  | 
 
 
 
 
 | 102 | if(!selectedImage.isEmpty()){ | 
 
 
 
 
 | 103 |  | 
 
 
 
 
 | 104 | this->middleImage->setText(selectedImage); | 
 
 
 
 
 | 105 | this->middleImage->setToolTip(selectedImage); | 
 
 
 
 
 | 106 |  | 
 
 
 
 
 | 107 | this->middleImage->setPixmap( selectedImage ); | 
 
 
 
 
 | 108 |  | 
 
 
 
 
 | 109 | // Thanks bukkfa! | 
 
 
 
 
 | 110 | // http://stackoverflow.com/questions/5653114/display-image-in-qt-to-fit-label-size | 
 
 
 
 
 | 111 | this->middleImage->setScaledContents( true ); | 
 
 
 
 
 | 112 | this->addRemoveImageButton->setToolTip("Click to remove the image"); | 
 
 
 
 
 | 113 | this->addRemoveImageButton->setIcon(QIcon(":/new/icons/abort.png")); | 
 
 
 
 
 | 114 | } | 
 
 
 
 
 | 115 | } | 
 
 
 
 
 | 116 | else{ | 
 
 
 
 
 | 117 | this->middleImage->setToolTip(""); | 
 
 
 
 
 | 118 | this->middleImage->clear(); | 
 
 
 
 
 | 119 | this->middleImage->setText("No image selected"); | 
 
 
 
 
 | 120 | this->addRemoveImageButton->setToolTip("Click to add an image"); | 
 
 
 
 
 | 121 | this->addRemoveImageButton->setIcon(QIcon(":/new/icons/plus.png")); | 
 
 
 
 
 | 122 | } | 
 
 
 
 
 | 123 | } |