File indexing completed on 2024-05-12 05:09:48
0001 /*************************************************************************** 0002 Copyright (C) 2006-2009 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "previewdialog.h" 0026 #include "../entryview.h" 0027 #include "../entry.h" 0028 #include "../images/imagefactory.h" // for StyleOptions 0029 0030 #include <KLocalizedString> 0031 0032 #include <QTemporaryDir> 0033 #include <QDialogButtonBox> 0034 #include <QPushButton> 0035 #include <QVBoxLayout> 0036 0037 using Tellico::GUI::PreviewDialog; 0038 0039 PreviewDialog::PreviewDialog(QWidget* parent_) 0040 : QDialog(parent_) 0041 , m_tempDir(new QTemporaryDir()) { 0042 setModal(false); 0043 setWindowTitle(i18n("Template Preview")); 0044 0045 QVBoxLayout* mainLayout = new QVBoxLayout; 0046 setLayout(mainLayout); 0047 0048 m_view = new EntryView(this); 0049 #ifdef USE_KHTML 0050 mainLayout->addWidget(m_view->view()); 0051 #else 0052 mainLayout->addWidget(m_view); 0053 #endif 0054 0055 QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); 0056 QPushButton* okButton = buttonBox->button(QDialogButtonBox::Ok); 0057 okButton->setDefault(true); 0058 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0059 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0060 mainLayout->addWidget(buttonBox); 0061 0062 resize(QSize(800, 600)); 0063 0064 m_tempDir->setAutoRemove(true); 0065 } 0066 0067 PreviewDialog::~PreviewDialog() { 0068 delete m_tempDir; 0069 m_tempDir = nullptr; 0070 } 0071 0072 void PreviewDialog::setXSLTFile(const QString& file_) { 0073 m_view->setXSLTFile(file_); 0074 } 0075 0076 void PreviewDialog::setXSLTOptions(int collectionType_, Tellico::StyleOptions options_) { 0077 options_.imgDir = m_tempDir->path(); // images always get written to temp dir 0078 ImageFactory::createStyleImages(collectionType_, options_); 0079 m_view->setXSLTOptions(options_); 0080 } 0081 0082 void PreviewDialog::showEntry(Tellico::Data::EntryPtr entry_) { 0083 m_view->showEntry(entry_); 0084 }