| 1 | #include "slidepage.h" |
| 2 | |
| 3 | SlidePage::SlidePage(int radius, QString name, QWidget *parent) : |
| 4 | QWidget(parent), |
| 5 | cornerRadius(radius), |
| 6 | pageName(name) |
| 7 | { |
| 8 | //if(parent) |
| 9 | // resize(parent->width() * 0.8 <= preferWidth ? parent->width() * 0.8 : preferWidth, parent->height()); |
| 10 | resize(parent->width() * 0.3 <= preferWidth ? preferWidth : parent->width() * 0.3, parent->height()); |
| 11 | this->move(QPoint(-this->width() - 30, 0)); |
| 12 | |
| 13 | pageContentContainer = new ScrollAreaCustom(this); |
| 14 | //> note: Important!!! |
| 15 | pageContentContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 16 | |
| 17 | nameLabel = new QLabel(pageName, this); |
| 18 | textFont.setStyleStrategy(QFont::PreferAntialias); |
| 19 | nameLabel->setFont(textFont); |
| 20 | |
| 21 | backIcon = new customIcon(":/icons/icons/back.svg", "", 5, this); |
| 22 | |
| 23 | opacity = new QGraphicsOpacityEffect(this); |
| 24 | opacity->setOpacity(0); |
| 25 | pageContentContainer->setGraphicsEffect(opacity); |
| 26 | nameLabel->setGraphicsEffect(opacity); |
| 27 | |
| 28 | QString style; |
| 29 | style = "background-color:white;border-radius:" + QString::asprintf("%d", cornerRadius) + "px"; |
| 30 | bgWidget = new QWidget(this); |
| 31 | bgWidget->lower(); |
| 32 | bgWidget->resize(this->size()); |
| 33 | bgWidget->setStyleSheet(style); |
| 34 | bgWidget->show(); |
| 35 | |
| 36 | /* Intialize layout */ |
| 37 | QVBoxLayout *mainLayout = new QVBoxLayout(this); |
| 38 | mainLayout->setContentsMargins(20, 40, 20, 20); |
| 39 | QWidget *titleBar = new QWidget(this); |
| 40 | QHBoxLayout *titleLayout = new QHBoxLayout(titleBar); |
| 41 | titleLayout->setAlignment(Qt::AlignLeft); |
| 42 | titleBar->setLayout(titleLayout); |
| 43 | titleLayout->addWidget(backIcon); |
| 44 | titleLayout->addWidget(nameLabel); |
| 45 | mainLayout->addWidget(titleBar); |
| 46 | mainLayout->addWidget(pageContentContainer); |
| 47 | mainLayout->setAlignment(Qt::AlignTop); |
| 48 | this->setLayout(mainLayout); |
| 49 | |
| 50 | sheildLayer = new SheildLayer(this->parentWidget()); |
| 51 | sheildLayer->resize(this->parentWidget()->size()); |
| 52 | sheildLayer->setGraphicsEffect(opacity); |
| 53 | sheildLayer->setMouseTracking(true); |
| 54 | connect(sheildLayer, &SheildLayer::clicked, this, [=](){slideOut();setFocus();}); |
| 55 | |
| 56 | /* Set shadow */ |
| 57 | QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); |
| 58 | shadow->setBlurRadius(30); |
| 59 | shadow->setColor(QColor(0, 0, 0)); |
| 60 | shadow->setOffset(0, 0); |