Subversion Repositories Scribus

Rev

Rev 16904 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/


#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QStackedWidget>

#if defined(_MSC_VER)
#define _USE_MATH_DEFINES
#endif
#include <cmath>
#include "commonstrings.h"
#include "pageitem.h"
#include "propertiespalette_content.h"
#include "propertywidget_group.h"
#include "propertywidget_image.h"
#include "propertywidget_text.h"
#include "scribus.h"
#include "scribuscore.h"
#include "scribusdoc.h"
#include "scribusview.h"
#include "selection.h"
#include "units.h"
#include "undomanager.h"
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
#include "text/nlsconfig.h"

//using namespace std;

PropertiesPalette_Content::PropertiesPalette_Content( QWidget* parent) : ScDockPalette( parent, "ContentPalette", 0)
{
        m_ScMW = 0;
        m_doc  = 0;
        m_item = 0;
        m_unitRatio = 1.0;

        //setObjectName(QString::fromLocal8Bit("FramePalette"));
        setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));

        QWidget* widget = new QWidget(this);
        widget->setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum));

        QVBoxLayout* vboxLayout = new QVBoxLayout();
        vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
        vboxLayout->setMargin(5);
        vboxLayout->setSpacing(1);
        vboxLayout->setAlignment(Qt::AlignTop);
       
        QHBoxLayout* hboxLayout = new QHBoxLayout();
        hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));

        QButtonGroup* buttonGroup = new QButtonGroup(widget);
        buttonGroup->setObjectName(QString::fromUtf8("buttonGroup"));

        QToolButton* imageButton = new QToolButton(widget);
        imageButton->setObjectName(QString::fromUtf8("imageButton"));
        imageButton->setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
        imageButton->setIcon( loadIcon("16/insert-image.png") );
        imageButton->setText("");
        hboxLayout->addWidget(imageButton);
       
        QToolButton* textButton = new QToolButton(widget);
        textButton->setObjectName(QString::fromUtf8("textButton"));
        textButton->setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
        textButton->setIcon( loadIcon("16/insert-text-frame.png") );
        textButton->setText("");
        hboxLayout->addWidget(textButton);

        QToolButton* groupButton = new QToolButton(widget);
        groupButton->setObjectName(QString::fromUtf8("groupButton"));
        groupButton->setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
        //groupButton->setIcon( loadIcon("16/insert-table.png") );
        groupButton->setText("");
        hboxLayout->addWidget(groupButton);

        QToolButton* tableButton = new QToolButton(widget);
        tableButton->setObjectName(QString::fromUtf8("tableButton"));
        tableButton->setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
        tableButton->setIcon( loadIcon("16/insert-table.png") );
        tableButton->setText("");
        hboxLayout->addWidget(tableButton);
       
        vboxLayout->addLayout(hboxLayout);

        buttonGroup->addButton(imageButton);
        buttonGroup->addButton(textButton);
        buttonGroup->addButton(groupButton);
        buttonGroup->addButton(tableButton);
        imageButton->setChecked(true);
       
        QStackedWidget* widgetStack = new QStackedWidget(this);
        widgetStack->setObjectName(QString::fromUtf8("widgetStack"));
       
        imageWidget = new PropertyWidget_Image(widgetStack);
        imageWidget->setObjectName(QString::fromUtf8("imagePropsWidget"));
        widgetStack->addWidget(imageWidget);

        textWidget = new PropertyWidget_Text(widgetStack);
        textWidget->setObjectName(QString::fromUtf8("textPropsWidget"));
        widgetStack->addWidget(textWidget);

        groupWidget = new PropertyWidget_Group(widgetStack);
        groupWidget->setObjectName(QString::fromUtf8("groupPropsWidget"));
        widgetStack->addWidget(groupWidget);
       
        vboxLayout->addWidget(widgetStack);
       
        widget->setLayout(vboxLayout);

        setWidget(widget);

        languageChange();

        connect(buttonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(onButtonGroupClicked(QAbstractButton*)));
}

void PropertiesPalette_Content::onButtonGroupClicked(QAbstractButton* button)
{
        QStackedWidget* widgetStack = this->findChild<QStackedWidget*>("widgetStack");
        if (button->objectName() == "imageButton")
                widgetStack->setCurrentIndex(0);
        if (button->objectName() == "textButton")
                widgetStack->setCurrentIndex(1);
        if (button->objectName() == "groupButton")
                widgetStack->setCurrentIndex(2);
}

void PropertiesPalette_Content::connectSignals()
{

}

void PropertiesPalette_Content::disconnectSignals()
{

}

void PropertiesPalette_Content::enableFromSelection(void)
{
        bool enabled = false;
        if (m_doc && m_item)
        {
                enabled = true;
        }
        setEnabled(enabled);
}

void PropertiesPalette_Content::setMainWindow(ScribusMainWindow* mw)
{
        m_ScMW=mw;
        QPoint p1 = mapToGlobal(pos());
        QPoint p2 = m_ScMW->mapFromGlobal(p1);
        //Qt4 reparent(m_ScMW, this->getWFlags(), p2);
        setParent(m_ScMW);
        move(p2);

        groupWidget->setMainWindow(mw);
        imageWidget->setMainWindow(mw);
        textWidget->setMainWindow(mw);
}

void PropertiesPalette_Content::setDoc(ScribusDoc *d)
{
        if((d == (ScribusDoc*) m_doc) || (m_ScMW && m_ScMW->scriptIsRunning()))
                return;

        if (m_doc)
        {
                disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
                disconnect(m_doc             , SIGNAL(docChanged())      , this, SLOT(handleSelectionChanged()));
        }

        m_doc = d;
        m_item = NULL;

        groupWidget->setDoc(m_doc);
        imageWidget->setDoc(m_doc);
        textWidget->setDoc(m_doc);

        if (m_doc.isNull())
        {
                disconnectSignals();
                return;
        }

        m_unitRatio   = m_doc->unitRatio();
        m_unitIndex   = m_doc->unitIndex();

        connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
        connect(m_doc             , SIGNAL(docChanged())      , this, SLOT(handleSelectionChanged()));
}

void PropertiesPalette_Content::setCurrentItem(PageItem *item)
{
        if (!m_ScMW || m_ScMW->scriptIsRunning())
                return;
        //CB We shouldnt really need to process this if our item is the same one
        //maybe we do if the item has been changed by scripter.. but that should probably
        //set some status if so.
        //FIXME: This wont work until when a canvas deselect happens, m_item must be NULL.
        //if (m_item == i)
        //      return;

        if (item && m_doc.isNull())
                setDoc(item->doc());

        m_item = item;

        disconnectSignals();
        enableFromSelection();

        if (m_item)
        {
                connectSignals();
        }
}

void PropertiesPalette_Content::handleSelectionChanged()
{
        if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning())
                return;

        PageItem* currItem = currentItemFromSelection();
        setCurrentItem(currItem);

        updateGeometry();
        repaint();
}

void PropertiesPalette_Content::changeEvent(QEvent *e)
{
        if (e->type() == QEvent::LanguageChange)
        {
                languageChange();
                return;
        }
        ScDockPalette::changeEvent(e);
}

void PropertiesPalette_Content::languageChange()
{
        setWindowTitle( tr("Content Properties"));

        groupWidget->languageChange();
        imageWidget->languageChange();
        textWidget->languageChange();
}

void PropertiesPalette_Content::unitChange()
{
        if (!m_doc)
                return;

        m_unitRatio = m_doc->unitRatio();
        m_unitIndex = m_doc->unitIndex();

        groupWidget->unitChange();
        imageWidget->unitChange();
        textWidget->unitChange();
}