Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/checkbox.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/lineedit.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/fxsettings.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/palettecmd.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzfolders.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qframe></qframe>
Toshihiro Shimizu 890ddd
#include <qlayout></qlayout>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qpushbutton></qpushbutton>
Toshihiro Shimizu 890ddd
#include <qapplication></qapplication>
Toshihiro Shimizu 890ddd
#include <qstyle></qstyle>
Toshihiro Shimizu 890ddd
#include <qbuttongroup></qbuttongroup>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qradiobutton></qradiobutton>
Toshihiro Shimizu 890ddd
#include <qthread></qthread>
shun_iwasawa 4ada6a
#include <qdesktopwidget></qdesktopwidget>
Jeremy Bullock b53dba
#include <qcheckbox></qcheckbox>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// boost includes
Toshihiro Shimizu 890ddd
#include <boost algorithm="" any_of.hpp="" cxx11=""></boost>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
shun-iwasawa 22412d
QString DialogTitle = QObject::tr("OpenToonz 1.2");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
QPixmap getMsgBoxPixmap(MsgType type) {
Shinya Kitaoka 120a6e
  int iconSize =
Shinya Kitaoka 120a6e
      QApplication::style()->pixelMetric(QStyle::PM_MessageBoxIconSize);
Shinya Kitaoka 120a6e
  QIcon msgBoxIcon;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (type) {
Shinya Kitaoka 120a6e
  case DVGui::INFORMATION:
Shinya Kitaoka 120a6e
    msgBoxIcon =
Shinya Kitaoka 120a6e
        QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case DVGui::WARNING:
Shinya Kitaoka 120a6e
    msgBoxIcon =
Shinya Kitaoka 120a6e
        QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case DVGui::CRITICAL:
Shinya Kitaoka 120a6e
    msgBoxIcon =
Shinya Kitaoka 120a6e
        QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case DVGui::QUESTION:
Shinya Kitaoka 120a6e
    msgBoxIcon =
Shinya Kitaoka 120a6e
        QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!msgBoxIcon.isNull()) return msgBoxIcon.pixmap(iconSize, iconSize);
Shinya Kitaoka 120a6e
  return QPixmap();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString getMsgBoxTitle(MsgType type) {
Shinya Kitaoka 120a6e
  QString title = DialogTitle + " - ";
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (type) {
Shinya Kitaoka 120a6e
  case DVGui::INFORMATION:
Shinya Kitaoka 120a6e
    title.append(QObject::tr("Information"));
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case DVGui::WARNING:
Shinya Kitaoka 120a6e
    title.append(QObject::tr("Warning"));
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case DVGui::CRITICAL:
Shinya Kitaoka 120a6e
    title.append(QObject::tr("Critical"));
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case DVGui::QUESTION:
Shinya Kitaoka 120a6e
    title.append(QObject::tr("Question"));
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return title;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Separator
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 59484b
Separator::Separator(QString name, QWidget *parent, bool isHorizontal)
shun-iwasawa 59484b
    : QFrame(parent), m_name(name), m_isHorizontal(isHorizontal) {
Shinya Kitaoka 120a6e
  //	if(m_name.isEmpty())
Shinya Kitaoka 120a6e
  //		setMinimumSize(1,1);
Shinya Kitaoka 120a6e
  //	else
Shinya Kitaoka 120a6e
  setMinimumSize(1, 15);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Separator::~Separator() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Separator::paintEvent(QPaintEvent *) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
  ParamsPage *page = dynamic_cast<paramspage *="">(parentWidget());</paramspage>
Shinya Kitaoka 120a6e
  if (!page)
shun_iwasawa b102ca
    p.setPen(palette().alternateBase().color());
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    p.setPen(page->getTextColor());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QRect contents(contentsRect());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int textWidth = p.fontMetrics().width(m_name);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.drawText(contents.left(), 10, m_name);
shun-iwasawa c86c5d
Shinya Kitaoka d1f6c4
  // make the line semi-transparent
shun-iwasawa c86c5d
  QColor lineColor = palette().alternateBase().color();
shun-iwasawa c86c5d
  lineColor.setAlpha(128);
shun-iwasawa c86c5d
shun-iwasawa c86c5d
  p.setPen(lineColor);
Shinya Kitaoka 120a6e
  int h = contents.height();
Shinya Kitaoka 120a6e
  if (m_isHorizontal) {
Shinya Kitaoka 120a6e
    int y     = contents.center().y();
Shinya Kitaoka 120a6e
    int space = (textWidth == 0) ? 0 : 8;
Shinya Kitaoka 120a6e
    p.drawLine(textWidth + space, y, contents.width(), y);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    double w       = width();
Shinya Kitaoka 120a6e
    int space      = (textWidth == 0) ? 0 : 2;
Shinya Kitaoka 120a6e
    int x0         = (w > textWidth) ? w * 0.5 : (double)textWidth * 0.5;
Shinya Kitaoka 120a6e
    int textHeghit = (space == 0) ? 0 : p.fontMetrics().height();
Shinya Kitaoka 120a6e
    p.drawLine(x0, textHeghit + space, x0, contents.bottom());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \class DVGui::Dialog
Shinya Kitaoka 120a6e
                \brief The Dialog class is the base class of dialog windows.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                Inherits \b QDialog.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                A dialog window is a top-level window, defined in \b QDialog,
Shinya Kitaoka 120a6e
this class provides
Shinya Kitaoka 120a6e
                a collection of functions to manage \b QDialog widget
Shinya Kitaoka 120a6e
visualization.
Shinya Kitaoka 120a6e
                Dialog window can be modal or modeless, from this it depends
Shinya Kitaoka 120a6e
dialog visualization.
Shinya Kitaoka 120a6e
                You set your dialog to modal or modeless directly in
Shinya Kitaoka 120a6e
constructor, with \b bool
Shinya Kitaoka 120a6e
                hasButton, in fact if the dialog has button then is modal too.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                If dialog is \b modal it's composed of two part, two \b QFrame;
Shinya Kitaoka 120a6e
the first, \b main
Shinya Kitaoka 120a6e
                \b part at top of dialog, contains a vertical box layout \b
Shinya Kitaoka 120a6e
QVBoxLayout, the second,
Shinya Kitaoka 120a6e
                \b button \b part at bottom, contains an horizontal box layout
Shinya Kitaoka 120a6e
\b QHBoxLayout.
Shinya Kitaoka 120a6e
                Else if dialog is modeless it is composed only of first part, to
Shinya Kitaoka 120a6e
be more precise,
Shinya Kitaoka 120a6e
                it is composed of a \b QFrame containing a vertical box layout
Shinya Kitaoka 120a6e
\b QVBoxLayout.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                The first part of dialog can be implemented using different
Shinya Kitaoka 120a6e
objects. You can manage
Shinya Kitaoka 120a6e
                directly vertical box layout, insert widget addWidget(), or
Shinya Kitaoka 120a6e
layout addLayout(), set
Shinya Kitaoka 120a6e
                border and spacing, using setTopMargin() and setTopSpacing(), or
Shinya Kitaoka 120a6e
insert a spece,
Shinya Kitaoka 120a6e
                addSpacing().
Shinya Kitaoka 120a6e
\n	If you need an horizontal layout you can use an implemented horizontal
Shinya Kitaoka 120a6e
box layout;
Shinya Kitaoka 120a6e
                the function beginHLayout() initialize the horizontal box
Shinya Kitaoka 120a6e
layout, a collection of
Shinya Kitaoka 120a6e
                function permit to insert object in this layout; at the end you
Shinya Kitaoka 120a6e
must recall
Shinya Kitaoka 120a6e
                endVLayout(), this add horizontal layout to first part of
Shinya Kitaoka 120a6e
dialog.
Shinya Kitaoka 120a6e
                This struct permit you to allign the object you insert.
Shinya Kitaoka 120a6e
\n	If you need vertical layout you can use an implemented vertical box
Shinya Kitaoka 120a6e
layout composed
Shinya Kitaoka 120a6e
                of two column, the function beginVLayout() initialize the
Shinya Kitaoka 120a6e
vertical box layout,
Shinya Kitaoka 120a6e
                a collection of function permit to insert object in this layout.
Shinya Kitaoka 120a6e
                All this functions insert a pair of object in two vertical
Shinya Kitaoka 120a6e
layout and permit
Shinya Kitaoka 120a6e
                to allign the objects, all pairs you insert are tabulated.
Shinya Kitaoka 120a6e
                At the end you must recall endVLayout(), this add vertical
Shinya Kitaoka 120a6e
layout to first part of
Shinya Kitaoka 120a6e
                dialog.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                The second part of dialog may be implemented if dialog is modal.
Shinya Kitaoka 120a6e
                It's possible insert one, two or three widget in its horizontal
Shinya Kitaoka 120a6e
box layout using
Shinya Kitaoka 120a6e
                addButtonBarWidget(), or clear all widget using
Shinya Kitaoka 120a6e
clearButtonBar(). You can also
Shinya Kitaoka 120a6e
                set margin and spacing with setButtonBarMargin() and
Shinya Kitaoka 120a6e
setButtonBarSpacing() functions.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
QSettings *Dialog::m_settings = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Dialog::Dialog(QWidget *parent, bool hasButton, bool hasFixedSize,
Shinya Kitaoka 120a6e
               const QString &name)
Shinya Kitaoka 120a6e
    : QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Shinya Kitaoka 120a6e
                          Qt::WindowCloseButtonHint)
Shinya Kitaoka 120a6e
    , m_hasButton(hasButton)
Shinya Kitaoka 120a6e
    , m_mainHLayout(0)
Shinya Kitaoka 120a6e
    , m_leftVLayout(0)
Shinya Kitaoka 120a6e
    , m_rightVLayout(0)
Shinya Kitaoka 120a6e
    , m_isMainVLayout(false)
Shinya Kitaoka 120a6e
    , m_isMainHLayout(false)
Shinya Kitaoka 120a6e
    , m_layoutSpacing(5)
Shinya Kitaoka 120a6e
    , m_layoutMargin(0)
Shinya Kitaoka 120a6e
    , m_labelWidth(100)
Shinya Kitaoka 120a6e
    , m_name() {
Shinya Kitaoka 120a6e
  QVBoxLayout *mainLayout = new QVBoxLayout;
Shinya Kitaoka 120a6e
  mainLayout->setMargin(0);
Shinya Kitaoka 120a6e
  mainLayout->setSpacing(0);
Shinya Kitaoka 120a6e
  m_mainFrame = new QFrame(this);
Shinya Kitaoka 120a6e
  m_mainFrame->setObjectName("dialogMainFrame");
Shinya Kitaoka 120a6e
  m_mainFrame->setMinimumHeight(41);
Shinya Kitaoka 120a6e
  m_mainFrame->setFrameStyle(QFrame::StyledPanel);
Shinya Kitaoka 120a6e
  m_topLayout = new QVBoxLayout;
Shinya Kitaoka 120a6e
  m_topLayout->setMargin(12);
Shinya Kitaoka 120a6e
  m_topLayout->setSpacing(m_layoutSpacing);
Shinya Kitaoka 120a6e
  m_topLayout->setAlignment(Qt::AlignCenter);
Shinya Kitaoka 120a6e
  m_mainFrame->setLayout(m_topLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  mainLayout->addWidget(m_mainFrame);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_hasButton) {
Shinya Kitaoka 120a6e
    // The dialog is modal
Shinya Kitaoka 120a6e
    setModal(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_buttonFrame = new QFrame(this);
Shinya Kitaoka 120a6e
    m_buttonFrame->setObjectName("dialogButtonFrame");
Shinya Kitaoka 120a6e
    m_buttonFrame->setFrameStyle(QFrame::StyledPanel);
Shinya Kitaoka 120a6e
    m_buttonFrame->setFixedHeight(45);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_buttonLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
    m_buttonLayout->setMargin(0);
Shinya Kitaoka 120a6e
    m_buttonLayout->setSpacing(20);
Shinya Kitaoka 120a6e
    m_buttonLayout->setAlignment(Qt::AlignHCenter);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QVBoxLayout *buttonFrameLayout = new QVBoxLayout;
Shinya Kitaoka 120a6e
    buttonFrameLayout->setAlignment(Qt::AlignVCenter);
Shinya Kitaoka 120a6e
    buttonFrameLayout->addLayout(m_buttonLayout);
Shinya Kitaoka 120a6e
    m_buttonFrame->setLayout(buttonFrameLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_buttonFrame);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (hasFixedSize)
Shinya Kitaoka 120a6e
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    mainLayout->setSizeConstraint(QLayout::SetMinimumSize);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  setLayout(mainLayout);
Shinya Kitaoka 120a6e
// this->setGeometry(30, 30, 300, 300);
Toshihiro Shimizu 890ddd
#ifdef MACOSX
Shinya Kitaoka 120a6e
  setWindowFlags(Qt::Tool);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!m_settings) {
Shinya Kitaoka 120a6e
    TFilePath layoutDir = ToonzFolder::getMyModuleDir();
Shinya Kitaoka 120a6e
    TFilePath savePath  = layoutDir + TFilePath("popups.ini");
Shinya Kitaoka 120a6e
    m_settings =
Shinya Kitaoka 120a6e
        new QSettings(QString::fromStdWString(savePath.getWideString()),
Shinya Kitaoka 120a6e
                      QSettings::IniFormat);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (name == QString()) return;
Shinya Kitaoka 120a6e
  m_name      = name + "DialogGeometry";
Shinya Kitaoka 120a6e
  QString geo = m_settings->value(m_name).toString();
Shinya Kitaoka 120a6e
  if (geo != QString()) {
Shinya Kitaoka 120a6e
    QStringList values = geo.split(" ");
Shinya Kitaoka 120a6e
    assert(values.size() == 4);
shun_iwasawa 4ada6a
    // Ensure that the dialog is visible in the screen.
shun_iwasawa 4ada6a
    // The dialog opens with some offset to bottom-right direction
shun_iwasawa 4ada6a
    // if a flag Qt::WindowMaximizeButtonHint is set. (e.g. PencilTestPopup)
shun_iwasawa 4ada6a
    // Therefore, if the dialog is moved to the bottom-end of the screen,
shun_iwasawa 4ada6a
    // it will be got out of the screen on the next launch.
shun_iwasawa 4ada6a
    // The following position adjustment will also prevent such behavior.
Jeremy Bullock 6095dd
Jeremy Bullock 6095dd
    // try and get active screen
Jeremy Bullock 6095dd
    if (parent != NULL) {
Jeremy Bullock 6095dd
      m_currentScreen = QApplication::desktop()->screenNumber(parent);
Jeremy Bullock 6095dd
    }
Jeremy Bullock 6095dd
    QRect screen = QApplication::desktop()->availableGeometry(m_currentScreen);
Jeremy Bullock 6095dd
    int x        = values.at(0).toInt();
Jeremy Bullock 6095dd
    int y        = values.at(1).toInt();
Jeremy Bullock 6095dd
Jeremy Bullock 6095dd
    // make sure that the window is visible on the screen
Jeremy Bullock 6095dd
    // all popups will popup on the active window the first time
Jeremy Bullock 6095dd
    // so popups moved to other monitors will be moved back
Jeremy Bullock 6095dd
    // when restarting OpenToonz.
Jeremy Bullock 6095dd
Jeremy Bullock 6095dd
    // This may be somewhat annoying if a user REALLY wants the popup
Jeremy Bullock 6095dd
    // on another monitor by default, but this is better than
Jeremy Bullock 6095dd
    // a user thinking the program is broken because they didn't notice
Jeremy Bullock 6095dd
    // the popup on another monitor
Jeremy Bullock 6095dd
    if (x > screen.right() - 50) x  = screen.right() - 50;
Jeremy Bullock 6095dd
    if (x < screen.left()) x        = screen.left();
Jeremy Bullock 6095dd
    if (y > screen.bottom() - 90) y = screen.bottom() - 90;
Jeremy Bullock 6095dd
    if (y < screen.top()) y         = screen.top();
shun_iwasawa 4ada6a
    setGeometry(x, y, values.at(2).toInt(), values.at(3).toInt());
Jeremy Bullock 6095dd
    m_settings->setValue(m_name,
Jeremy Bullock 6095dd
                         QString::number(x) + " " + QString::number(y) + " " +
Jeremy Bullock 6095dd
                             QString::number(values.at(2).toInt()) + " " +
Jeremy Bullock 6095dd
                             QString::number(values.at(3).toInt()));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Dialog::~Dialog() {}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Dialog::moveEvent(QMoveEvent *e) {
Shinya Kitaoka 120a6e
  if (m_name == QString()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QRect r = geometry();
Shinya Kitaoka 120a6e
  m_settings->setValue(m_name, QString::number(r.left()) + " " +
Shinya Kitaoka 120a6e
                                   QString::number(r.top()) + " " +
Shinya Kitaoka 120a6e
                                   QString::number(r.width()) + " " +
Shinya Kitaoka 120a6e
                                   QString::number(r.height()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Dialog::resizeEvent(QResizeEvent *e) {
Shinya Kitaoka 120a6e
  if (Preferences::instance()->getCurrentLanguage() != "English") {
Shinya Kitaoka 120a6e
    QSize t = this->size();
Shinya Kitaoka 120a6e
    QLabel *s;
Shinya Kitaoka 120a6e
    foreach (s, m_labelList)
Shinya Kitaoka 120a6e
      s->setFixedWidth(t.width() * .35);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_name == QString()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QRect r = geometry();
Shinya Kitaoka 120a6e
  m_settings->setValue(m_name, QString::number(r.left()) + " " +
Shinya Kitaoka 120a6e
                                   QString::number(r.top()) + " " +
Shinya Kitaoka 120a6e
                                   QString::number(r.width()) + " " +
Shinya Kitaoka 120a6e
                                   QString::number(r.height()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! By default, QDialogs always reset position/size upon hide events. However,
Shinya Kitaoka 120a6e
//! we want to prevent such behaviour on Toonz Dialogs - this method is
Shinya Kitaoka 120a6e
//! reimplemented
Toshihiro Shimizu 890ddd
//! for this purpose.
Shinya Kitaoka 120a6e
void Dialog::hideEvent(QHideEvent *event) {
Jeremy Bullock 6095dd
  int x = pos().rx();
Jeremy Bullock 6095dd
  int y = pos().ry();
Jeremy Bullock 6095dd
  // make sure the dialog is actually visible on a screen
Jeremy Bullock 6095dd
  int screenCount = QApplication::desktop()->screenCount();
Jeremy Bullock 6095dd
  int currentScreen;
Jeremy Bullock 6095dd
  for (int i = 0; i < screenCount; i++) {
Jeremy Bullock 6095dd
    if (QApplication::desktop()->screenGeometry(i).contains(pos())) {
Jeremy Bullock 6095dd
      currentScreen = i;
Jeremy Bullock 6095dd
      break;
Jeremy Bullock 6095dd
    } else {
Jeremy Bullock 6095dd
      // if not - put it back on the main window
Jeremy Bullock 6095dd
      currentScreen = m_currentScreen;
Jeremy Bullock 6095dd
    }
Jeremy Bullock 6095dd
  }
Jeremy Bullock 6095dd
  QRect screen = QApplication::desktop()->availableGeometry(currentScreen);
Jeremy Bullock 6095dd
Jeremy Bullock 6095dd
  if (x > screen.right() - 50) x  = screen.right() - 50;
Jeremy Bullock 6095dd
  if (x < screen.left()) x        = screen.left();
Jeremy Bullock 6095dd
  if (y > screen.bottom() - 90) y = screen.bottom() - 90;
Jeremy Bullock 6095dd
  if (y < screen.top()) y         = screen.top();
Jeremy Bullock 6095dd
  move(QPoint(x, y));
Shinya Kitaoka 120a6e
  resize(size());
Jeremy Bullock 6095dd
  QRect r = geometry();
Jeremy Bullock 6095dd
  m_settings->setValue(m_name, QString::number(r.left()) + " " +
Jeremy Bullock 6095dd
                                   QString::number(r.top()) + " " +
Jeremy Bullock 6095dd
                                   QString::number(r.width()) + " " +
Jeremy Bullock 6095dd
                                   QString::number(r.height()));
Shinya Kitaoka 120a6e
  emit dialogClosed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create the new layouts (2 Vertical) for main part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::beginVLayout() {
Shinya Kitaoka 120a6e
  m_isMainVLayout = true;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_leftVLayout = new QVBoxLayout;
Shinya Kitaoka 120a6e
  m_leftVLayout->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  m_leftVLayout->setSpacing(m_layoutSpacing);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_rightVLayout = new QVBoxLayout;
Shinya Kitaoka 120a6e
  m_rightVLayout->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  m_rightVLayout->setSpacing(m_layoutSpacing);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add to main part of dialog the Vertical Layouts ,insert them in a orizontal
Shinya Kitaoka 120a6e
                layout to form two column, set Vertical Layouts to 0 .
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::endVLayout() {
Shinya Kitaoka 120a6e
  if (!m_leftVLayout || !m_rightVLayout) return;
Shinya Kitaoka 120a6e
  m_isMainVLayout = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QHBoxLayout *layout = new QHBoxLayout;
Shinya Kitaoka 120a6e
  layout->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  layout->setSpacing(m_layoutSpacing);
Shinya Kitaoka 120a6e
  layout->setSizeConstraint(QLayout::SetFixedSize);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  layout->addLayout(m_leftVLayout);
Shinya Kitaoka 120a6e
  layout->setAlignment(m_leftVLayout, Qt::AlignLeft);
Shinya Kitaoka 120a6e
  layout->addLayout(m_rightVLayout);
Shinya Kitaoka 120a6e
  layout->setAlignment(m_rightVLayout, Qt::AlignLeft);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  addLayout(layout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_leftVLayout  = 0;
Shinya Kitaoka 120a6e
  m_rightVLayout = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create a new Horizontal Layout for main part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::beginHLayout() {
Shinya Kitaoka 120a6e
  m_isMainHLayout = true;
Shinya Kitaoka 120a6e
  m_mainHLayout   = new QHBoxLayout;
Shinya Kitaoka 120a6e
  m_mainHLayout->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  m_mainHLayout->setSpacing(m_layoutSpacing);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add to main part of dialog the Horizontal Layout  and set it to 0.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::endHLayout() {
Shinya Kitaoka 120a6e
  m_isMainHLayout = false;
Shinya Kitaoka 120a6e
  if (!m_mainHLayout) return;
Shinya Kitaoka 120a6e
  addLayout(m_mainHLayout);
Shinya Kitaoka 120a6e
  m_mainHLayout = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a widget \b widget to main part of dialog. If vertical layout is
Shinya Kitaoka 120a6e
                initialized add widget in right column if \b isRight is true,
Shinya Kitaoka 120a6e
   otherwise in
Shinya Kitaoka 120a6e
                left column. \b isRight by default is true.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addWidget(QWidget *widget, bool isRight) {
Shinya Kitaoka 120a6e
  if (m_isMainVLayout) {
Shinya Kitaoka 120a6e
    assert(m_leftVLayout && m_rightVLayout);
Shinya Kitaoka 120a6e
    QWidget *w = new QWidget();
Shinya Kitaoka 120a6e
    int h      = widget->height() + m_layoutSpacing;
Shinya Kitaoka 120a6e
    if (isRight) {
Shinya Kitaoka 120a6e
      m_leftVLayout->addSpacing(h);
Shinya Kitaoka 120a6e
      m_rightVLayout->addWidget(widget);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_leftVLayout->addWidget(widget, 1, Qt::AlignRight);
Shinya Kitaoka 120a6e
      m_rightVLayout->addSpacing(h);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (m_isMainHLayout) {
Shinya Kitaoka 120a6e
    assert(m_mainHLayout);
Shinya Kitaoka 120a6e
    m_mainHLayout->addWidget(widget);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_topLayout->addWidget(widget);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a pair [widget,widget] to main part of dialog.
Shinya Kitaoka 120a6e
\n	If vertical and horizontal layout are not initialized create an
Shinya Kitaoka 120a6e
horizontal
Shinya Kitaoka 120a6e
                box layout containing the two widgets and recall \b addLayout().
Shinya Kitaoka 120a6e
                If vertical layout is current add the pair to vertical layout of
Shinya Kitaoka 120a6e
main part,
Shinya Kitaoka 120a6e
                \b firstW on first column and \b secondW on second column.
Shinya Kitaoka 120a6e
                Else if horizontal layout is current create an horizontal box
Shinya Kitaoka 120a6e
layout containing
Shinya Kitaoka 120a6e
                \b firstW and \b secondW and add it to horizontal layout.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addWidgets(QWidget *firstW, QWidget *secondW) {
Shinya Kitaoka 120a6e
  if (m_isMainVLayout) {
Shinya Kitaoka 120a6e
    assert(m_leftVLayout && m_rightVLayout);
Shinya Kitaoka 120a6e
    m_leftVLayout->addWidget(firstW);
Shinya Kitaoka 120a6e
    m_rightVLayout->addWidget(secondW);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  QHBoxLayout *pairLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
  pairLayout->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  pairLayout->setSpacing(m_layoutSpacing);
Shinya Kitaoka 120a6e
  pairLayout->addWidget(firstW);
Shinya Kitaoka 120a6e
  pairLayout->addWidget(secondW);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_isMainHLayout) {
Shinya Kitaoka 120a6e
    assert(m_mainHLayout);
Shinya Kitaoka 120a6e
    m_mainHLayout->addLayout(pairLayout);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  addLayout(pairLayout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a pair [label,widget] to main part of dialog, label is created from
Shinya Kitaoka 120a6e
                \b QString \b nameLabel.
Toshihiro Shimizu 890ddd
\n	Recall \b addWidgets(QWdiget* firstW, QWdiget* secondW).
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addWidget(QString labelName, QWidget *widget) {
Shinya Kitaoka 120a6e
  QLabel *label = new QLabel(labelName);
Shinya Kitaoka 120a6e
  m_labelList.push_back(label);
Shinya Kitaoka 120a6e
  label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
  label->setFixedSize(m_labelWidth, widget->height());
Shinya Kitaoka 120a6e
  addWidgets(label, widget);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a layout \b layout to main part of dialog. If vertical layout is
Shinya Kitaoka 120a6e
                initialized add widget in right column if \b isRight is true,
Shinya Kitaoka 120a6e
   otherwise in
Shinya Kitaoka 120a6e
                left column. \b isRight by default is true.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addLayout(QLayout *layout, bool isRight) {
Shinya Kitaoka 120a6e
  if (m_isMainVLayout) {
Shinya Kitaoka 120a6e
    assert(m_leftVLayout && m_rightVLayout);
Shinya Kitaoka 120a6e
    int h = layout->itemAt(0)->widget()->height() + m_layoutSpacing;
Shinya Kitaoka 120a6e
    if (isRight) {
Shinya Kitaoka 120a6e
      m_leftVLayout->addSpacing(h);
Shinya Kitaoka 120a6e
      m_rightVLayout->addLayout(layout);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_leftVLayout->addLayout(layout);
Shinya Kitaoka 120a6e
      m_rightVLayout->addSpacing(h);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (m_isMainHLayout) {
Shinya Kitaoka 120a6e
    assert(m_mainHLayout);
Shinya Kitaoka 120a6e
    m_mainHLayout->addLayout(layout);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_topLayout->addLayout(layout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a pair [widget,layout] to main part of dialog.
Shinya Kitaoka 120a6e
\n	If vertical and horizontal layout are not initialized create an
Shinya Kitaoka 120a6e
horizontal
Shinya Kitaoka 120a6e
                box layout containing \b widget and \b layout and recall \b
Shinya Kitaoka 120a6e
addLayout().
Shinya Kitaoka 120a6e
                If vertical layout is current add the pair [label,layout] to
Shinya Kitaoka 120a6e
vertical layout
Shinya Kitaoka 120a6e
                of main part, label on first column and layout on second column.
Shinya Kitaoka 120a6e
                Else if horizontal layout is current create an horizontal box
Shinya Kitaoka 120a6e
layout containing
Shinya Kitaoka 120a6e
                \b widget and \b layout and add it to horizontal layout.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addWidgetLayout(QWidget *widget, QLayout *layout) {
Shinya Kitaoka 120a6e
  layout->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  layout->setSpacing(m_layoutSpacing);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_isMainVLayout) {
Shinya Kitaoka 120a6e
    assert(m_leftVLayout && m_rightVLayout);
Shinya Kitaoka 120a6e
    m_leftVLayout->addWidget(widget);
Shinya Kitaoka 120a6e
    m_rightVLayout->addLayout(layout);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QHBoxLayout *pairLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
  pairLayout->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  pairLayout->setSpacing(m_layoutSpacing);
Shinya Kitaoka 120a6e
  pairLayout->addWidget(widget);
Shinya Kitaoka 120a6e
  pairLayout->addLayout(layout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_isMainHLayout) {
Shinya Kitaoka 120a6e
    assert(m_mainHLayout);
Shinya Kitaoka 120a6e
    m_mainHLayout->addLayout(pairLayout);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  addLayout(pairLayout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a pair [label,layout] to main part of dialog, label is created from
Shinya Kitaoka 120a6e
                \b QString \b nameLabel.
Toshihiro Shimizu 890ddd
\n	Recall \b addWidgetLayout(QWdiget* widget, QWdiget* layout).
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addLayout(QString labelName, QLayout *layout) {
Shinya Kitaoka 120a6e
  QLabel *label = new QLabel(labelName);
Shinya Kitaoka 120a6e
  m_labelList.push_back(label);
Shinya Kitaoka 120a6e
  label->setFixedWidth(m_labelWidth);
Shinya Kitaoka 120a6e
  label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
  addWidgetLayout(label, layout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a pair [layout,layout] to main part of dialog.
Shinya Kitaoka 120a6e
\n	If vertical and horizontal layout are not initialized create an
Shinya Kitaoka 120a6e
horizontal
Shinya Kitaoka 120a6e
                box layout containing the two layouts and recall \b addLayout().
Shinya Kitaoka 120a6e
                If vertical layout is current add the pair [layout,layout] to
Shinya Kitaoka 120a6e
vertical layout
Shinya Kitaoka 120a6e
                of main part, \b firstL on first column and \b secondL on second
Shinya Kitaoka 120a6e
column.
Shinya Kitaoka 120a6e
                Else if horizontal layout is current create an horizontal box
Shinya Kitaoka 120a6e
layout containing
Shinya Kitaoka 120a6e
                \b firstL and \b secondL and add it to horizontal layout.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addLayouts(QLayout *firstL, QLayout *secondL) {
Shinya Kitaoka 120a6e
  firstL->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  firstL->setSpacing(m_layoutSpacing);
Shinya Kitaoka 120a6e
  secondL->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  secondL->setSpacing(m_layoutSpacing);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_isMainVLayout) {
Shinya Kitaoka 120a6e
    assert(m_leftVLayout && m_rightVLayout);
Shinya Kitaoka 120a6e
    m_leftVLayout->addLayout(firstL);
Shinya Kitaoka 120a6e
    m_rightVLayout->addLayout(secondL);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QHBoxLayout *pairLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
  pairLayout->setMargin(m_layoutMargin);
Shinya Kitaoka 120a6e
  pairLayout->setSpacing(m_layoutSpacing);
Shinya Kitaoka 120a6e
  pairLayout->addLayout(firstL);
Shinya Kitaoka 120a6e
  pairLayout->addLayout(secondL);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_isMainHLayout) {
Shinya Kitaoka 120a6e
    assert(m_mainHLayout);
Shinya Kitaoka 120a6e
    m_mainHLayout->addLayout(pairLayout);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  addLayout(pairLayout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add spacing \b spacing to main part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addSpacing(int spacing) {
Shinya Kitaoka 120a6e
  if (m_isMainVLayout) {
Shinya Kitaoka 120a6e
    assert(m_leftVLayout && m_rightVLayout);
Shinya Kitaoka 120a6e
    m_leftVLayout->addSpacing(spacing);
Shinya Kitaoka 120a6e
    m_rightVLayout->addSpacing(spacing);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (m_isMainHLayout) {
Shinya Kitaoka 120a6e
    assert(m_mainHLayout);
Shinya Kitaoka 120a6e
    m_mainHLayout->addSpacing(spacing);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_topLayout->addSpacing(spacing);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a separator \b Separator to main part of dialog.
Shinya Kitaoka 120a6e
                If vertical layout is initialized add an horizontal separator.
Shinya Kitaoka 120a6e
                If horizontal layout is initialized add a vertical separator.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addSeparator(QString name) {
Shinya Kitaoka 120a6e
  Separator *separator = new Separator(name);
Shinya Kitaoka 120a6e
  if (m_isMainVLayout) {
Shinya Kitaoka 120a6e
    assert(m_leftVLayout && m_rightVLayout);
Shinya Kitaoka 120a6e
    endVLayout();
Shinya Kitaoka 120a6e
    addWidget(separator);
Shinya Kitaoka 120a6e
    beginVLayout();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (m_isMainHLayout) {
Shinya Kitaoka 120a6e
    assert(m_mainHLayout);
Shinya Kitaoka 120a6e
    separator->setOrientation(false);
Shinya Kitaoka 120a6e
    m_mainHLayout->addWidget(separator);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  addWidget(separator);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set the alignement of the main layout
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::setAlignment(Qt::Alignment alignment) {
Shinya Kitaoka 120a6e
  m_mainFrame->layout()->setAlignment(alignment);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set to \b spacing spacing of main part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::setTopSpacing(int spacing) {
Shinya Kitaoka 120a6e
  m_layoutSpacing = spacing;
Shinya Kitaoka 120a6e
  m_topLayout->setSpacing(spacing);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Dialog::setLabelWidth(int labelWidth) { m_labelWidth = labelWidth; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set to \b spacing spacing of all layout inserted in main part of dialog,
Shinya Kitaoka 120a6e
                horizontal layout and vertical layout.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::setLayoutInsertedSpacing(int spacing) {
Shinya Kitaoka 120a6e
  m_layoutSpacing = spacing;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return the spacing of all layout inserted in main part of dialog,
Shinya Kitaoka 120a6e
                horizontal layout and vertical layout.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
int Dialog::getLayoutInsertedSpacing() { return m_layoutSpacing; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set to \b margin margin of main part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::setTopMargin(int margin) { m_topLayout->setMargin(margin); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set to \b margin margin of button part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::setButtonBarMargin(int margin) {
Shinya Kitaoka 120a6e
  m_buttonLayout->setMargin(margin);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set to \b spacing spacing of button part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::setButtonBarSpacing(int spacing) {
Shinya Kitaoka 120a6e
  m_buttonLayout->setSpacing(spacing);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a widget to the button part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addButtonBarWidget(QWidget *widget) {
Shinya Kitaoka 120a6e
  widget->setMinimumSize(65, 25);
Shinya Kitaoka 120a6e
  assert(m_hasButton);
Shinya Kitaoka 120a6e
  if (m_hasButton) {
Shinya Kitaoka 120a6e
    m_buttonLayout->addWidget(widget);
Shinya Kitaoka 120a6e
    m_buttonBarWidgets.push_back(widget);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Remove all widget from the button part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::clearButtonBar() {
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)m_buttonBarWidgets.size(); i++) {
Shinya Kitaoka 120a6e
    m_buttonLayout->removeWidget(m_buttonBarWidgets[i]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_buttonBarWidgets.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add two widget to the button part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addButtonBarWidget(QWidget *first, QWidget *second) {
Shinya Kitaoka 120a6e
  first->setMinimumSize(65, 25);
Shinya Kitaoka 120a6e
  second->setMinimumSize(65, 25);
Shinya Kitaoka 120a6e
  assert(m_hasButton);
Shinya Kitaoka 120a6e
  if (m_hasButton) {
Shinya Kitaoka 120a6e
    m_buttonLayout->addWidget(first);
Shinya Kitaoka 120a6e
    m_buttonLayout->addWidget(second);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add three widget to the button part of dialog.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void Dialog::addButtonBarWidget(QWidget *first, QWidget *second,
Shinya Kitaoka 120a6e
                                QWidget *third) {
Shinya Kitaoka 120a6e
  first->setMinimumSize(65, 25);
Shinya Kitaoka 120a6e
  second->setMinimumSize(65, 25);
Shinya Kitaoka 120a6e
  third->setMinimumSize(65, 25);
Shinya Kitaoka 120a6e
  assert(m_hasButton);
Shinya Kitaoka 120a6e
  if (m_hasButton) {
Shinya Kitaoka 120a6e
    m_buttonLayout->addWidget(first);
Shinya Kitaoka 120a6e
    m_buttonLayout->addWidget(second);
Shinya Kitaoka 120a6e
    m_buttonLayout->addWidget(third);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Jeremy Bullock 33e7d1
//-----------------------------------------------------------------------------
Jeremy Bullock 33e7d1
/*! Add four widget to the button part of dialog.
Jeremy Bullock 33e7d1
*/
Jeremy Bullock 33e7d1
void Dialog::addButtonBarWidget(QWidget *first, QWidget *second, QWidget *third,
Jeremy Bullock 33e7d1
                                QWidget *fourth) {
Jeremy Bullock 33e7d1
  first->setMinimumSize(65, 25);
Jeremy Bullock 33e7d1
  second->setMinimumSize(65, 25);
Jeremy Bullock 33e7d1
  third->setMinimumSize(65, 25);
Jeremy Bullock 33e7d1
  assert(m_hasButton);
Jeremy Bullock 33e7d1
  if (m_hasButton) {
Jeremy Bullock 33e7d1
    m_buttonLayout->addWidget(first);
Jeremy Bullock 33e7d1
    m_buttonLayout->addWidget(second);
Jeremy Bullock 33e7d1
    m_buttonLayout->addWidget(third);
Jeremy Bullock 33e7d1
    m_buttonLayout->addWidget(fourth);
Jeremy Bullock 33e7d1
  }
Jeremy Bullock 33e7d1
}
Jeremy Bullock 33e7d1
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
shun-iwasawa 133733
MessageAndCheckboxDialog::MessageAndCheckboxDialog(
shun-iwasawa 133733
    QWidget *parent, bool hasButton, bool hasFixedSize, const QString &name,
shun-iwasawa 133733
    Qt::CheckState checkButtonState)
shun-iwasawa 133733
    : Dialog(parent, hasButton, hasFixedSize, name)
shun-iwasawa 133733
    , m_checked(checkButtonState) {}
Jeremy Bullock b53dba
Jeremy Bullock b53dba
//=============================================================================
Jeremy Bullock b53dba
Jeremy Bullock b53dba
void MessageAndCheckboxDialog::onButtonPressed(int id) { done(id); }
Jeremy Bullock b53dba
Jeremy Bullock b53dba
//=============================================================================
Jeremy Bullock b53dba
Jeremy Bullock b53dba
void MessageAndCheckboxDialog::onCheckboxChanged(int checked) {
Jeremy Bullock b53dba
  m_checked = checked;
Jeremy Bullock b53dba
}
Jeremy Bullock b53dba
Jeremy Bullock b53dba
//=============================================================================
Jeremy Bullock b53dba
Shinya Kitaoka 120a6e
RadioButtonDialog::RadioButtonDialog(const QString &labelText,
Shinya Kitaoka 120a6e
                                     const QList<qstring> &radioButtonList,</qstring>
Shinya Kitaoka 120a6e
                                     QWidget *parent, Qt::WindowFlags f)
Shinya Kitaoka 120a6e
    : Dialog(parent, true, true), m_result(1) {
Jeremy Bullock b53dba
  setWindowTitle(tr("OpenToonz"));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setMinimumSize(20, 20);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  beginVLayout();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QLabel *label = new QLabel(labelText);
Shinya Kitaoka 120a6e
  label->setAlignment(Qt::AlignLeft);
Shinya Kitaoka 120a6e
  label->setFixedHeight(2 * WidgetHeight);
Shinya Kitaoka 120a6e
  addWidget(label);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QButtonGroup *buttonGroup = new QButtonGroup(this);
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < radioButtonList.count(); i++) {
Shinya Kitaoka 120a6e
    QRadioButton *radioButton = new QRadioButton(radioButtonList.at(i));
Shinya Kitaoka 120a6e
    if (i == m_result - 1) radioButton->setChecked(true);
Shinya Kitaoka 120a6e
    radioButton->setFixedHeight(WidgetHeight);
Shinya Kitaoka 120a6e
    buttonGroup->addButton(radioButton);
Shinya Kitaoka 120a6e
    buttonGroup->setId(radioButton, i);
Shinya Kitaoka 120a6e
    addWidget(radioButton);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool ret = connect(buttonGroup, SIGNAL(buttonClicked(int)),
Shinya Kitaoka 120a6e
                     SLOT(onButtonClicked(int)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  endVLayout();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QPushButton *applyButton = new QPushButton(QObject::tr("Apply"));
Shinya Kitaoka 120a6e
  ret = ret && connect(applyButton, SIGNAL(pressed()), this, SLOT(onApply()));
Shinya Kitaoka 120a6e
  QPushButton *cancelButton = new QPushButton(QObject::tr("Cancel"));
Shinya Kitaoka 120a6e
  ret = ret && connect(cancelButton, SIGNAL(pressed()), this, SLOT(onCancel()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  addButtonBarWidget(applyButton, cancelButton);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(ret);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RadioButtonDialog::onButtonClicked(int id) {
Shinya Kitaoka 120a6e
  // Add "1" because "0" is cancel button.
Shinya Kitaoka 120a6e
  m_result = id + 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RadioButtonDialog::onCancel() { done(0); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RadioButtonDialog::onApply() { done(m_result); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int DVGui::RadioButtonMsgBox(MsgType type, const QString &labelText,
Shinya Kitaoka 120a6e
                             const QList<qstring> &radioButtonList,</qstring>
Shinya Kitaoka 120a6e
                             QWidget *parent) {
Shinya Kitaoka 120a6e
  RadioButtonDialog *dialog =
Shinya Kitaoka 120a6e
      new RadioButtonDialog(labelText, radioButtonList, parent);
Shinya Kitaoka 120a6e
  QString msgBoxTitle = getMsgBoxTitle(DVGui::WARNING);
Shinya Kitaoka 120a6e
  dialog->setWindowTitle(msgBoxTitle);
Shinya Kitaoka 120a6e
  return dialog->exec();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ProgressDialog::ProgressDialog(const QString &labelText,
Shinya Kitaoka 120a6e
                               const QString &cancelButtonText, int minimum,
Shinya Kitaoka 120a6e
                               int maximum, QWidget *parent, Qt::WindowFlags f)
Shinya Kitaoka 120a6e
    : Dialog(parent, true, true), m_isCanceled(false) {
turtletooth 04d8fd
  setWindowTitle(tr("OpenToonz"));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setMinimumSize(20, 20);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  beginVLayout();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_label = new QLabel(this);
Shinya Kitaoka 120a6e
  m_label->setText(labelText);
Shinya Kitaoka 120a6e
  addWidget(m_label);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_progressBar = new QProgressBar(this);
Shinya Kitaoka 120a6e
  m_progressBar->setRange(minimum, maximum);
Shinya Kitaoka 120a6e
  m_progressBar->setMinimumWidth(250);
Shinya Kitaoka 120a6e
  addWidget(m_progressBar);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  endVLayout();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!cancelButtonText.isEmpty())
Shinya Kitaoka 120a6e
    setCancelButton(new QPushButton(cancelButtonText));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ProgressDialog::setLabelText(const QString &text) {
Shinya Kitaoka 120a6e
  m_label->setText(text);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ProgressDialog::setCancelButton(QPushButton *cancelButton) {
Shinya Kitaoka 120a6e
  m_cancelButton = cancelButton;
Shinya Kitaoka 120a6e
  bool ret = connect(cancelButton, SIGNAL(pressed()), this, SLOT(onCancel()));
Shinya Kitaoka 120a6e
  ret =
Shinya Kitaoka 120a6e
      ret && connect(cancelButton, SIGNAL(pressed()), this, SIGNAL(canceled()));
Shinya Kitaoka 120a6e
  assert(ret);
Shinya Kitaoka 120a6e
  addButtonBarWidget(m_cancelButton);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int ProgressDialog::maximum() { return m_progressBar->maximum(); }
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ProgressDialog::setMaximum(int maximum) {
Shinya Kitaoka 120a6e
  m_progressBar->setMaximum(maximum);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int ProgressDialog::minimum() { return m_progressBar->minimum(); }
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ProgressDialog::setMinimum(int minimum) {
Shinya Kitaoka 120a6e
  m_progressBar->setMinimum(minimum);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int ProgressDialog::value() { return m_progressBar->value(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ProgressDialog::setValue(int progress) {
Shinya Kitaoka 120a6e
  m_progressBar->setValue(progress);
Shinya Kitaoka 120a6e
  if (isModal()) qApp->processEvents();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ProgressDialog::reset() { m_progressBar->reset(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ProgressDialog::wasCanceled() const { return m_isCanceled; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ProgressDialog::onCancel() {
Shinya Kitaoka 120a6e
  m_isCanceled = true;
Shinya Kitaoka 120a6e
  reset();
Shinya Kitaoka 120a6e
  hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int DVGui::MsgBox(MsgType type, const QString &text,
Shinya Kitaoka 120a6e
                  const std::vector<qstring> &buttons, int defaultButtonIndex,</qstring>
Shinya Kitaoka 120a6e
                  QWidget *parent) {
Shinya Kitaoka 120a6e
  Dialog dialog(parent, true);
Shinya Kitaoka 120a6e
  dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint);
Shinya Kitaoka 120a6e
  dialog.setAlignment(Qt::AlignLeft);
Shinya Kitaoka 120a6e
  QString msgBoxTitle = getMsgBoxTitle(type);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  dialog.setWindowTitle(msgBoxTitle);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QLabel *mainTextLabel = new QLabel(text, &dialog);
Shinya Kitaoka 120a6e
  QPixmap iconPixmap    = getMsgBoxPixmap(type);
Shinya Kitaoka 120a6e
  if (!iconPixmap.isNull()) {
Shinya Kitaoka 120a6e
    QLabel *iconLabel = new QLabel(&dialog);
Shinya Kitaoka 120a6e
    iconLabel->setPixmap(iconPixmap);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QHBoxLayout *mainLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
    mainLayout->addWidget(iconLabel);
Shinya Kitaoka 120a6e
    mainLayout->addSpacing(16);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(mainTextLabel);
Shinya Kitaoka 120a6e
    dialog.addLayout(mainLayout);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    dialog.addWidget(mainTextLabel);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // ButtonGroup: is used only to retrieve the clicked button
Shinya Kitaoka 120a6e
  QButtonGroup *buttonGroup = new QButtonGroup(&dialog);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)buttons.size(); i++) {
Shinya Kitaoka 120a6e
    QPushButton *button = new QPushButton(buttons[i], &dialog);
Shinya Kitaoka 120a6e
    if (defaultButtonIndex == i)
Shinya Kitaoka 120a6e
      button->setDefault(true);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      button->setDefault(false);
Shinya Kitaoka 120a6e
    dialog.addButtonBarWidget(button);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    buttonGroup->addButton(button, i + 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), &dialog,
Shinya Kitaoka 120a6e
                   SLOT(done(int)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  dialog.raise();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return dialog.exec();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DVGui::MsgBoxInPopup(MsgType type, const QString &text) {
Shinya Kitaoka 120a6e
  // this function must be called by the main thread only
Shinya Kitaoka 120a6e
  // (only the main thread should access directly the GUI)
Shinya Kitaoka 120a6e
  // (note: working thread can and should call MsgBox(type,text) instead; see
Shinya Kitaoka 120a6e
  // tmsgcore.h)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Q_ASSERT(QApplication::instance()->thread() == QThread::currentThread());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // a working thread can trigger a call to this function (by the main thread)
Shinya Kitaoka 120a6e
  // also when a popup is already open
Shinya Kitaoka 120a6e
  // therefore we need a messageQueue
Shinya Kitaoka 120a6e
  // note: no mutex are needed because only the main thread call this function
Shinya Kitaoka 120a6e
  static QList<qpair<msgtype, qstring="">> messageQueue;</qpair<msgtype,>
Shinya Kitaoka 120a6e
  static bool popupIsOpen = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  messageQueue.append(qMakePair(type, text));
Shinya Kitaoka 120a6e
  if (popupIsOpen) return;
Shinya Kitaoka 120a6e
  popupIsOpen = true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Dialog dialog(0, true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint);
Shinya Kitaoka 120a6e
  dialog.setAlignment(Qt::AlignLeft);
Shinya Kitaoka 120a6e
  QLabel *mainTextLabel = new QLabel("", &dialog);
Shinya Kitaoka 120a6e
  mainTextLabel->setMinimumWidth(400);
Shinya Kitaoka 120a6e
  QLabel *iconLabel = new QLabel(&dialog);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QHBoxLayout *mainLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
  mainLayout->addWidget(iconLabel);
Shinya Kitaoka 120a6e
  mainLayout->addStretch();
Shinya Kitaoka 120a6e
  mainLayout->addWidget(mainTextLabel);
Shinya Kitaoka 120a6e
  mainLayout->addStretch();
Shinya Kitaoka 120a6e
  dialog.addLayout(mainLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // ButtonGroup: is used only to retrieve the clicked button
Shinya Kitaoka 120a6e
  QButtonGroup *buttonGroup = new QButtonGroup(&dialog);
Shinya Kitaoka 120a6e
  QPushButton *button       = new QPushButton(QPushButton::tr("OK"), &dialog);
Shinya Kitaoka 120a6e
  button->setDefault(true);
Shinya Kitaoka 120a6e
  dialog.addButtonBarWidget(button);
Shinya Kitaoka 120a6e
  buttonGroup->addButton(button, 1);
Shinya Kitaoka 120a6e
  QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), &dialog,
Shinya Kitaoka 120a6e
                   SLOT(done(int)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  while (!messageQueue.empty()) {
Shinya Kitaoka 120a6e
    MsgType type1 = messageQueue.first().first;
Shinya Kitaoka 120a6e
    QString text1 = messageQueue.first().second;
Shinya Kitaoka 120a6e
    messageQueue.pop_front();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    mainTextLabel->setText(text1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QString msgBoxTitle = getMsgBoxTitle(type1);
Shinya Kitaoka 120a6e
    dialog.setWindowTitle(msgBoxTitle);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QPixmap iconPixmap = getMsgBoxPixmap(type1);
Shinya Kitaoka 120a6e
    if (!iconPixmap.isNull()) {
Shinya Kitaoka 120a6e
      iconLabel->setPixmap(iconPixmap);
Shinya Kitaoka 120a6e
      iconLabel->setVisible(true);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      iconLabel->setVisible(false);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    dialog.raise();
Shinya Kitaoka 120a6e
    dialog.exec();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  }  // loop: open the next dialog in the queue
Shinya Kitaoka 120a6e
  popupIsOpen = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int DVGui::MsgBox(const QString &text, const QString &button1Text,
Shinya Kitaoka 120a6e
                  const QString &button2Text, const QString &button3Text,
Shinya Kitaoka 120a6e
                  int defaultButtonIndex, QWidget *parent) {
Shinya Kitaoka 120a6e
  Dialog dialog(parent, true);
Shinya Kitaoka 120a6e
  dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint);
Shinya Kitaoka 120a6e
  dialog.setAlignment(Qt::AlignLeft);
Shinya Kitaoka 120a6e
  QString msgBoxTitle = getMsgBoxTitle(QUESTION);
Shinya Kitaoka 120a6e
  dialog.setWindowTitle(msgBoxTitle);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QLabel *mainTextLabel = new QLabel(text, &dialog);
Shinya Kitaoka 120a6e
  QPixmap iconPixmap    = getMsgBoxPixmap(QUESTION);
Shinya Kitaoka 120a6e
  if (!iconPixmap.isNull()) {
Shinya Kitaoka 120a6e
    QLabel *iconLabel = new QLabel(&dialog);
Shinya Kitaoka 120a6e
    iconLabel->setPixmap(iconPixmap);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QHBoxLayout *mainLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
    mainLayout->addWidget(iconLabel);
Shinya Kitaoka 120a6e
    mainLayout->addSpacing(16);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(mainTextLabel);
Shinya Kitaoka 120a6e
    dialog.addLayout(mainLayout);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    dialog.addWidget(mainTextLabel);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // ButtonGroup: is used only to retrieve the clicked button
Shinya Kitaoka 120a6e
  QButtonGroup *buttonGroup = new QButtonGroup(&dialog);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPushButton *button1 = new QPushButton(button1Text, &dialog);
Shinya Kitaoka 120a6e
  button1->setDefault(false);
Shinya Kitaoka 120a6e
  if (defaultButtonIndex == 0) button1->setDefault(true);
Shinya Kitaoka 120a6e
  dialog.addButtonBarWidget(button1);
Shinya Kitaoka 120a6e
  buttonGroup->addButton(button1, 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPushButton *button2 = new QPushButton(button2Text, &dialog);
Shinya Kitaoka 120a6e
  button2->setDefault(false);
Shinya Kitaoka 120a6e
  if (defaultButtonIndex == 1) button2->setDefault(true);
Shinya Kitaoka 120a6e
  dialog.addButtonBarWidget(button2);
Shinya Kitaoka 120a6e
  buttonGroup->addButton(button2, 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPushButton *button3 = new QPushButton(button3Text, &dialog);
Shinya Kitaoka 120a6e
  button3->setDefault(false);
Shinya Kitaoka 120a6e
  if (defaultButtonIndex == 2) button3->setDefault(true);
Shinya Kitaoka 120a6e
  dialog.addButtonBarWidget(button3);
Shinya Kitaoka 120a6e
  buttonGroup->addButton(button3, 3);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), &dialog,
Shinya Kitaoka 120a6e
                   SLOT(done(int)));
Jeremy Bullock 33e7d1
  dialog.raise();
Jeremy Bullock 33e7d1
  return dialog.exec();
Jeremy Bullock 33e7d1
}
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
//-----------------------------------------------------------------------------
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
int DVGui::MsgBox(const QString &text, const QString &button1Text,
Jeremy Bullock 33e7d1
                  const QString &button2Text, const QString &button3Text,
Jeremy Bullock 33e7d1
                  const QString &button4Text, int defaultButtonIndex,
Jeremy Bullock 33e7d1
                  QWidget *parent) {
Jeremy Bullock 33e7d1
  Dialog dialog(parent, true);
Jeremy Bullock 33e7d1
  dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint);
Jeremy Bullock 33e7d1
  dialog.setAlignment(Qt::AlignLeft);
Jeremy Bullock 33e7d1
  QString msgBoxTitle = getMsgBoxTitle(QUESTION);
Jeremy Bullock 33e7d1
  dialog.setWindowTitle(msgBoxTitle);
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
  QLabel *mainTextLabel = new QLabel(text, &dialog);
Jeremy Bullock 33e7d1
  QPixmap iconPixmap    = getMsgBoxPixmap(QUESTION);
Jeremy Bullock 33e7d1
  if (!iconPixmap.isNull()) {
Jeremy Bullock 33e7d1
    QLabel *iconLabel = new QLabel(&dialog);
Jeremy Bullock 33e7d1
    iconLabel->setPixmap(iconPixmap);
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
    QHBoxLayout *mainLayout = new QHBoxLayout;
Jeremy Bullock 33e7d1
    mainLayout->addWidget(iconLabel);
Jeremy Bullock 33e7d1
    mainLayout->addSpacing(16);
Jeremy Bullock 33e7d1
    mainLayout->addWidget(mainTextLabel);
Jeremy Bullock 33e7d1
    dialog.addLayout(mainLayout);
Jeremy Bullock 33e7d1
  } else
Jeremy Bullock 33e7d1
    dialog.addWidget(mainTextLabel);
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
  // ButtonGroup: is used only to retrieve the clicked button
Jeremy Bullock 33e7d1
  QButtonGroup *buttonGroup = new QButtonGroup(&dialog);
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
  QPushButton *button1 = new QPushButton(button1Text, &dialog);
Jeremy Bullock 33e7d1
  button1->setDefault(false);
Jeremy Bullock 33e7d1
  if (defaultButtonIndex == 0) button1->setDefault(true);
Jeremy Bullock 33e7d1
  dialog.addButtonBarWidget(button1);
Jeremy Bullock 33e7d1
  buttonGroup->addButton(button1, 1);
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
  QPushButton *button2 = new QPushButton(button2Text, &dialog);
Jeremy Bullock 33e7d1
  button2->setDefault(false);
Jeremy Bullock 33e7d1
  if (defaultButtonIndex == 1) button2->setDefault(true);
Jeremy Bullock 33e7d1
  dialog.addButtonBarWidget(button2);
Jeremy Bullock 33e7d1
  buttonGroup->addButton(button2, 2);
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
  QPushButton *button3 = new QPushButton(button3Text, &dialog);
Jeremy Bullock 33e7d1
  button3->setDefault(false);
Jeremy Bullock 33e7d1
  if (defaultButtonIndex == 2) button3->setDefault(true);
Jeremy Bullock 33e7d1
  dialog.addButtonBarWidget(button3);
Jeremy Bullock 33e7d1
  buttonGroup->addButton(button3, 3);
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
  QPushButton *button4 = new QPushButton(button4Text, &dialog);
Jeremy Bullock 33e7d1
  button4->setDefault(false);
Jeremy Bullock 33e7d1
  if (defaultButtonIndex == 3) button4->setDefault(true);
Jeremy Bullock 33e7d1
  dialog.addButtonBarWidget(button4);
Jeremy Bullock 33e7d1
  buttonGroup->addButton(button4, 4);
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
  QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), &dialog,
Jeremy Bullock 33e7d1
                   SLOT(done(int)));
Shinya Kitaoka 120a6e
  dialog.raise();
Shinya Kitaoka 120a6e
  return dialog.exec();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int DVGui::MsgBox(const QString &text, const QString &button1,
Shinya Kitaoka 120a6e
                  const QString &button2, int defaultButtonIndex,
Shinya Kitaoka 120a6e
                  QWidget *parent) {
Shinya Kitaoka 120a6e
  Dialog dialog(parent, true);
Shinya Kitaoka 120a6e
  dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint);
Shinya Kitaoka 120a6e
  std::vector<qstring> buttons;</qstring>
Shinya Kitaoka 120a6e
  buttons.push_back(button1);
Shinya Kitaoka 120a6e
  buttons.push_back(button2);
Shinya Kitaoka 120a6e
  return DVGui::MsgBox(DVGui::QUESTION, text, buttons, defaultButtonIndex,
Shinya Kitaoka 120a6e
                       parent);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Dialog *DVGui::createMsgBox(MsgType type, const QString &text,
Shinya Kitaoka 120a6e
                            const QStringList &buttons, int defaultButtonIndex,
Shinya Kitaoka 120a6e
                            QWidget *parent) {
Shinya Kitaoka 120a6e
  Dialog *dialog = new Dialog(parent, true);
Shinya Kitaoka 120a6e
  dialog->setWindowFlags(dialog->windowFlags() | Qt::WindowStaysOnTopHint);
Shinya Kitaoka 120a6e
  dialog->setAlignment(Qt::AlignLeft);
Shinya Kitaoka 120a6e
  QString msgBoxTitle = getMsgBoxTitle(type);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  dialog->setWindowTitle(msgBoxTitle);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QLabel *mainTextLabel = new QLabel(text, dialog);
Shinya Kitaoka 120a6e
  mainTextLabel->setObjectName("Label");
Shinya Kitaoka 120a6e
  QPixmap iconPixmap = getMsgBoxPixmap(type);
Shinya Kitaoka 120a6e
  if (!iconPixmap.isNull()) {
Shinya Kitaoka 120a6e
    QLabel *iconLabel = new QLabel(dialog);
Shinya Kitaoka 120a6e
    iconLabel->setPixmap(iconPixmap);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QHBoxLayout *mainLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
    mainLayout->addWidget(iconLabel);
Shinya Kitaoka 120a6e
    mainLayout->addSpacing(16);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(mainTextLabel);
Shinya Kitaoka 120a6e
    dialog->addLayout(mainLayout);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    dialog->addWidget(mainTextLabel);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // ButtonGroup: is used only to retrieve the clicked button
Shinya Kitaoka 120a6e
  QButtonGroup *buttonGroup = new QButtonGroup(dialog);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)buttons.size(); i++) {
Shinya Kitaoka 120a6e
    QPushButton *button = new QPushButton(buttons[i], dialog);
Shinya Kitaoka 120a6e
    if (defaultButtonIndex == i)
Shinya Kitaoka 120a6e
      button->setDefault(true);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      button->setDefault(false);
Shinya Kitaoka 120a6e
    dialog->addButtonBarWidget(button);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    buttonGroup->addButton(button, i + 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), dialog,
Shinya Kitaoka 120a6e
                   SLOT(done(int)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return dialog;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock b53dba
MessageAndCheckboxDialog *DVGui::createMsgandCheckbox(
Jeremy Bullock b53dba
    MsgType type, const QString &text, const QString &checkBoxText,
shun-iwasawa 133733
    const QStringList &buttons, int defaultButtonIndex,
shun-iwasawa 133733
    Qt::CheckState defaultCheckBoxState, QWidget *parent) {
shun-iwasawa 133733
  MessageAndCheckboxDialog *dialog = new MessageAndCheckboxDialog(
shun-iwasawa 133733
      parent, true, true, "", defaultCheckBoxState);
Jeremy Bullock b53dba
  dialog->setWindowFlags(dialog->windowFlags() | Qt::WindowStaysOnTopHint);
Jeremy Bullock b53dba
  dialog->setAlignment(Qt::AlignLeft);
Jeremy Bullock b53dba
  QString msgBoxTitle = getMsgBoxTitle(type);
Jeremy Bullock b53dba
Jeremy Bullock b53dba
  dialog->setWindowTitle(msgBoxTitle);
Jeremy Bullock b53dba
Jeremy Bullock b53dba
  QLabel *mainTextLabel = new QLabel(text, dialog);
Jeremy Bullock b53dba
  mainTextLabel->setObjectName("Label");
Jeremy Bullock b53dba
  QPixmap iconPixmap = getMsgBoxPixmap(type);
Jeremy Bullock b53dba
  if (!iconPixmap.isNull()) {
Jeremy Bullock b53dba
    QLabel *iconLabel = new QLabel(dialog);
Jeremy Bullock b53dba
    iconLabel->setPixmap(iconPixmap);
Jeremy Bullock b53dba
Jeremy Bullock b53dba
    QHBoxLayout *mainLayout = new QHBoxLayout;
Jeremy Bullock b53dba
    mainLayout->addWidget(iconLabel);
Jeremy Bullock b53dba
    mainLayout->addSpacing(16);
Jeremy Bullock b53dba
    mainLayout->addWidget(mainTextLabel);
Jeremy Bullock b53dba
    dialog->addLayout(mainLayout);
Jeremy Bullock b53dba
  } else
Jeremy Bullock b53dba
    dialog->addWidget(mainTextLabel);
Jeremy Bullock b53dba
Jeremy Bullock b53dba
  // ButtonGroup: is used only to retrieve the clicked button
Jeremy Bullock b53dba
  QButtonGroup *buttonGroup = new QButtonGroup(dialog);
Jeremy Bullock b53dba
Jeremy Bullock b53dba
  for (int i = 0; i < (int)buttons.size(); i++) {
Jeremy Bullock b53dba
    QPushButton *button = new QPushButton(buttons[i], dialog);
Jeremy Bullock b53dba
    if (defaultButtonIndex == i)
Jeremy Bullock b53dba
      button->setDefault(true);
Jeremy Bullock b53dba
    else
Jeremy Bullock b53dba
      button->setDefault(false);
Jeremy Bullock b53dba
    dialog->addButtonBarWidget(button);
Jeremy Bullock b53dba
Jeremy Bullock b53dba
    buttonGroup->addButton(button, i + 1);
Jeremy Bullock b53dba
  }
Jeremy Bullock b53dba
shun-iwasawa 133733
  QCheckBox *dialogCheckBox   = new QCheckBox(checkBoxText, dialog);
Jeremy Bullock b53dba
  QHBoxLayout *checkBoxLayout = new QHBoxLayout;
Jeremy Bullock b53dba
  checkBoxLayout->addWidget(dialogCheckBox);
Jeremy Bullock b53dba
  checkBoxLayout->addStretch(0);
Jeremy Bullock b53dba
  dialog->addLayout(checkBoxLayout);
Jeremy Bullock b53dba
shun-iwasawa 133733
  dialogCheckBox->setCheckState(defaultCheckBoxState);
shun-iwasawa 133733
Jeremy Bullock b53dba
  QObject::connect(dialogCheckBox, SIGNAL(stateChanged(int)), dialog,
Jeremy Bullock b53dba
                   SLOT(onCheckboxChanged(int)));
Jeremy Bullock b53dba
  QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), dialog,
Jeremy Bullock b53dba
                   SLOT(onButtonPressed(int)));
Jeremy Bullock b53dba
Jeremy Bullock b53dba
  return dialog;
Jeremy Bullock b53dba
}
Jeremy Bullock b53dba
Jeremy Bullock b53dba
//-----------------------------------------------------------------------------
Jeremy Bullock b53dba
Toshihiro Shimizu 890ddd
QString DVGui::getText(const QString &title, const QString &labelText,
Shinya Kitaoka 120a6e
                       const QString &text, bool *ok) {
Shinya Kitaoka 120a6e
  Dialog dialog(0, true);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  dialog.setWindowTitle(title);
Shinya Kitaoka 120a6e
  dialog.setWindowFlags(Qt::WindowStaysOnTopHint | Qt::WindowTitleHint |
Shinya Kitaoka 120a6e
                        Qt::CustomizeWindowHint);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QVBoxLayout *layout = new QVBoxLayout(&dialog);
Shinya Kitaoka 120a6e
  dialog.addLayout(layout);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QLabel *label = new QLabel(labelText, &dialog);
Shinya Kitaoka 120a6e
  layout->addWidget(label);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  LineEdit *nameFld = new LineEdit(text, &dialog);
Shinya Kitaoka 120a6e
  layout->addWidget(nameFld);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QPushButton *okBtn = new QPushButton(dialog.tr("OK"), &dialog);
Shinya Kitaoka 120a6e
  okBtn->setDefault(true);
Shinya Kitaoka 120a6e
  QPushButton *cancelBtn = new QPushButton(dialog.tr("Cancel"), &dialog);
Shinya Kitaoka 120a6e
  QObject::connect(okBtn, SIGNAL(clicked()), &dialog, SLOT(accept()));
Shinya Kitaoka 120a6e
  QObject::connect(cancelBtn, SIGNAL(clicked()), &dialog, SLOT(reject()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  dialog.addButtonBarWidget(okBtn, cancelBtn);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int ret     = dialog.exec();
Shinya Kitaoka 120a6e
  if (ok) *ok = (ret == QDialog::Accepted);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return nameFld->text();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
bool isStyleIdInPalette(int styleId, const TPalette *palette) {
Shinya Kitaoka 120a6e
  if (palette->getStyleCount() == 0) return false;
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < palette->getPageCount(); i++) {
Shinya Kitaoka 120a6e
    const TPalette::Page *page = palette->getPage(i);
Shinya Kitaoka 120a6e
    if (!page) return false;  // La pagina dovrebbe esserci sempre
Shinya Kitaoka 120a6e
    int j;
Shinya Kitaoka 120a6e
    for (j = 0; j < page->getStyleCount(); j++)
Shinya Kitaoka 120a6e
      if (page->getStyleId(j) == styleId) return true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int DVGui::eraseStylesInDemand(TPalette *palette,
Shinya Kitaoka 120a6e
                               const TXsheetHandle *xsheetHandle,
Shinya Kitaoka 120a6e
                               TPalette *newPalette) {
Shinya Kitaoka 120a6e
  // Verifico se gli stili della paletta sono usati : eraseStylesInDemand()
Shinya Kitaoka 120a6e
  std::vector<int> styleIds;</int>
Shinya Kitaoka 120a6e
  int h;
Shinya Kitaoka 120a6e
  for (h = 0; h < palette->getPageCount(); h++) {
Shinya Kitaoka 120a6e
    TPalette::Page *page = palette->getPage(h);
Shinya Kitaoka 120a6e
    if (!page) continue;  // La pagina dovrebbe esserci sempre
Shinya Kitaoka 120a6e
    int k;
Shinya Kitaoka 120a6e
    for (k = 0; k < page->getStyleCount(); k++) {
Shinya Kitaoka 120a6e
      int styleId = page->getStyleId(k);
Shinya Kitaoka 120a6e
      bool isStyleIdInNewPalette =
Shinya Kitaoka 120a6e
          (!newPalette) ? false : isStyleIdInPalette(styleId, newPalette);
Shinya Kitaoka 120a6e
      if (styleId > 0 && !isStyleIdInNewPalette) styleIds.push_back(styleId);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return eraseStylesInDemand(palette, styleIds, xsheetHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int DVGui::eraseStylesInDemand(TPalette *palette, std::vector<int> styleIds,</int>
Shinya Kitaoka 120a6e
                               const TXsheetHandle *xsheetHandle) {
Shinya Kitaoka 120a6e
  struct locals {
Shinya Kitaoka 120a6e
    static bool isRasterLevel(const TXshSimpleLevel *level) {
Shinya Kitaoka 120a6e
      return level->getType() == TZP_XSHLEVEL ||
Shinya Kitaoka 120a6e
             level->getType() == OVL_XSHLEVEL;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  };  // locals
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Search xsheet levels attached to the palette
Shinya Kitaoka 120a6e
  std::set<txshsimplelevel *=""> levels;</txshsimplelevel>
Shinya Kitaoka 120a6e
  int row, column;
Shinya Kitaoka 120a6e
  findPaletteLevels(levels, row, column, palette, xsheetHandle->getXsheet());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool someStyleIsUsed =
Shinya Kitaoka 120a6e
      !levels.empty() ||
Shinya Kitaoka 120a6e
      styleIds.empty();  // I guess this is wrong... but I'm not touching it
Shinya Kitaoka 120a6e
  if (someStyleIsUsed) someStyleIsUsed = areStylesUsed(levels, styleIds);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!someStyleIsUsed) return 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // At least a style is selected and present in some level - ask user if and
Shinya Kitaoka 120a6e
  // how styles
Shinya Kitaoka 120a6e
  // should be deleted
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString question = QObject::tr(
Shinya Kitaoka 120a6e
                         "Styles you are going to delete are used to paint "
Shinya Kitaoka 120a6e
                         "lines and areas in the animation level.\n") +
Shinya Kitaoka 120a6e
                     QObject::tr("How do you want to proceed?");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int ret = DVGui::MsgBox(question, QObject::tr("Delete Styles Only"),
Shinya Kitaoka 120a6e
                          QObject::tr("Delete Styles, Lines and Areas"),
Shinya Kitaoka 120a6e
                          QObject::tr("Cancel"), 0);
Shinya Kitaoka 120a6e
  if (ret != 2) return (ret == 0 || ret == 3) ? 0 : 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Inform the user that case 2 will not produce an undo if a raster-based
Shinya Kitaoka 120a6e
  // level is detected
Shinya Kitaoka 120a6e
  if (boost::algorithm::any_of(levels, locals::isRasterLevel)) {
Shinya Kitaoka 120a6e
    std::vector<qstring> buttons(2);</qstring>
Shinya Kitaoka 120a6e
    buttons[0] = QObject::tr("Ok"), buttons[1] = QObject::tr("Cancel");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (DVGui::MsgBox(DVGui::WARNING,
Shinya Kitaoka 120a6e
                      QObject::tr("Deletion of Lines and Areas from "
Shinya Kitaoka 120a6e
                                  "raster-based levels is not undoable.\n"
Shinya Kitaoka 120a6e
                                  "Are you sure?"),
Shinya Kitaoka 120a6e
                      buttons) != 1)
Shinya Kitaoka 120a6e
      return 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QApplication::setOverrideCursor(Qt::WaitCursor);
Shinya Kitaoka 120a6e
  PaletteCmd::eraseStyles(levels, styleIds);
Shinya Kitaoka 120a6e
  QApplication::restoreOverrideCursor();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return (assert(ret == 2), ret);  // return 2 ?     :D
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DVGui::setDialogTitle(const QString &dialogTitle) {
Shinya Kitaoka 120a6e
  DialogTitle = dialogTitle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------