File indexing completed on 2023-05-30 10:45:27
0001 /* 0002 SPDX-FileCopyrightText: 2010 Peter Hedlund <peter.hedlund@kdemail.net> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "kwqtutorflashcard.h" 0007 0008 0009 #include "prefs.h" 0010 0011 KWQTutorFlashCard::KWQTutorFlashCard(QWidget* parent) : QWidget(parent) 0012 { 0013 m_label = 0; 0014 m_card = 0; 0015 0016 m_cardLayout = new QVBoxLayout(this); 0017 m_cardLayout->setContentsMargins(0, 0, 0, 0); 0018 m_cardLayout->setSpacing(0); 0019 setLayout(m_cardLayout); 0020 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Tool); 0021 init(); 0022 } 0023 0024 void KWQTutorFlashCard::init() 0025 { 0026 if (m_label != 0) { 0027 m_cardLayout->removeWidget(m_label); 0028 delete m_label; 0029 m_label = 0; 0030 } 0031 0032 if (m_card != 0) { 0033 m_cardLayout->removeWidget(m_card); 0034 delete m_card; 0035 m_card = 0; 0036 } 0037 0038 if (Prefs::tutorCardAppearance() == Prefs::EnumTutorCardAppearance::Minimalistic) { 0039 m_label = new QLabel(this); 0040 m_label->setMinimumWidth(80); 0041 m_label->setAlignment(Qt::AlignCenter); 0042 m_cardLayout->addWidget(m_label); 0043 } else { 0044 m_card = new KWQCardView(this); 0045 m_card->setTextFont(Prefs::frontFont()); 0046 m_cardLayout->addWidget(m_card); 0047 } 0048 0049 setText(m_text); 0050 } 0051 0052 void KWQTutorFlashCard::closeEvent (QCloseEvent* event) 0053 { 0054 Prefs::setTutorFlashCardGeometry(this->geometry()); //save flashcard window coords and geometry before closing it 0055 event->accept(); 0056 } 0057 0058 void KWQTutorFlashCard::setText(const QString & text) 0059 { 0060 m_text = text; 0061 if (m_label != 0) 0062 m_label->setText(text); 0063 if (m_card != 0) 0064 m_card->setText(text); 0065 }