/* * Copyright 2008 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ // Header include #include "ObjectUI.h" // Sigmodr includes #include "ValidationDialog.h" // Sigmod includes #include "../sigmod/Object.h" #include "../sigmod/Sigmod.h" // KDE includes #include #include #include #include Sigmodr::ObjectUI::ObjectUI(QWidget* parent) : QWidget(parent), m_changed(false), m_validator(NULL), m_object(NULL), m_object_mod(NULL) { setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(changed(bool)), SLOT(setChanged(bool))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint))); } Sigmodr::ObjectUI::~ObjectUI() { delete m_object_mod; } void Sigmodr::ObjectUI::reload() { refreshGui(); setGui(); } bool Sigmodr::ObjectUI::isChanged() const { return m_changed; } const Sigmod::Sigmod* Sigmodr::ObjectUI::sigmod() const { return m_object->sigmod(); } const Sigmod::Sigmod::Object* Sigmodr::ObjectUI::original() const { return m_object; } Sigmod::Object* Sigmodr::ObjectUI::original() { return m_object; } const Sigmod::Object* Sigmodr::ObjectUI::modified() const { return m_object_mod; } Sigmod::Object* Sigmodr::ObjectUI::modified() { return m_object_mod; } void Sigmodr::ObjectUI::setObjects(Sigmod::Object* original, Sigmod::Object* modified) { m_object = original; m_object_mod = modified; if (m_validator) delete m_validator; m_validator = new ValidationDialog(m_object, this); connect(m_object_mod, SIGNAL(changed()), this, SIGNAL(changed())); connect(m_object_mod, SIGNAL(changed()), this, SLOT(setGui())); connect(m_object_mod, SIGNAL(error(QString)), this, SLOT(setGui())); connect(m_object_mod, SIGNAL(error(QString)), this, SLOT(errorMessage(QString))); connect(m_object_mod, SIGNAL(warning(QString)), this, SLOT(warningMessage(QString))); init(); } void Sigmodr::ObjectUI::init() { initGui(); reload(); emit(changed(false)); } void Sigmodr::ObjectUI::setChanged(const bool changed) { m_changed = changed; } void Sigmodr::ObjectUI::errorMessage(const QString& message) { KMessageBox::error(this, message, "Error"); } void Sigmodr::ObjectUI::warningMessage(const QString& message) { KMessageBox::warningContinueCancel(this, message, "Warning"); } void Sigmodr::ObjectUI::initGui() { } void Sigmodr::ObjectUI::refreshGui() { } void Sigmodr::ObjectUI::contextMenu(const QPoint& pos) { KMenu* menu = new KMenu; menu->addAction("&Apply", this, SLOT(apply())); menu->addAction("&Discard", this, SLOT(discard())); menu->addSeparator(); KAction* validate = new KAction("&Validate", this); connect(validate, SIGNAL(triggered()), this, SLOT(validate())); validate->setEnabled(!m_changed); menu->addAction(validate); menu->popup(mapToGlobal(pos)); } void Sigmodr::ObjectUI::validate() { if (m_changed) apply(); m_validator->show(); }