1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8                           texttoolb.cpp  -  description
9                              -------------------
10     begin                : Sun Mar 10 2002
11     copyright            : (C) 2002 by Franz Schmid
12     email                : Franz.Schmid@altmuehlnet.de
13  ***************************************************************************/
14 
15 /***************************************************************************
16  *                                                                         *
17  *   This program is free software; you can redistribute it and/or modify  *
18  *   it under the terms of the GNU General Public License as published by  *
19  *   the Free Software Foundation; either version 2 of the License, or     *
20  *   (at your option) any later version.                                   *
21  *                                                                         *
22  ***************************************************************************/
23 
24 #include <QToolTip>
25 #include <QEvent>
26 #include <QMenu>
27 #include <QPixmap>
28 #include <QToolButton>
29 
30 #include "modetoolbar.h"
31 
32 #include "autoformbuttongroup.h"
33 #include "polyprops.h"
34 #include "scraction.h"
35 #include "scribus.h"
36 #include "scribusdoc.h"
37 #include "scrspinbox.h"
38 
ModeToolBar(ScribusMainWindow * parent)39 ModeToolBar::ModeToolBar(ScribusMainWindow* parent) : ScToolBar( tr("Tools"), "Tools", parent, Qt::Vertical)
40 {
41 	SubMode = 0;
42 	ValCount = 32;
43 	static double AutoShapes0[] = {0.0, 0.0, 0.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0,
44 									100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 0.0, 100.0, 0.0, 100.0,
45 									0.0, 100.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0};
46 	ShapeVals = AutoShapes0;
47 	m_ScMW=parent;
48 	this->addAction(m_ScMW->scrActions["toolsSelect"]);
49 	this->addAction(m_ScMW->scrActions["toolsInsertTextFrame"]);
50 	this->addAction(m_ScMW->scrActions["toolsInsertImageFrame"]);
51 	this->addAction(m_ScMW->scrActions["toolsInsertRenderFrame"]);
52 	this->addAction(m_ScMW->scrActions["toolsInsertTable"]);
53 
54 	this->addAction(m_ScMW->scrActions["toolsInsertShape"]);
55 	autoFormButtonGroup = new AutoformButtonGroup( nullptr );
56 	m_ScMW->scrActions["toolsInsertShape"]->setMenu(autoFormButtonGroup);
57 	QToolButton* tb = dynamic_cast<QToolButton*>(this->widgetForAction(m_ScMW->scrActions["toolsInsertShape"]));
58 	tb->setPopupMode(QToolButton::DelayedPopup);
59 	m_ScMW->scrActions["toolsInsertShape"]->setIcon(QIcon(autoFormButtonGroup->getIconPixmap(0,16)));
60 
61 	this->addAction(m_ScMW->scrActions["toolsInsertPolygon"]);
62 	insertPolygonButtonMenu = new QMenu();
63 	idInsertPolygonButtonMenu = insertPolygonButtonMenu->addAction( "Properties...", this, SLOT(GetPolyProps()));
64 	m_ScMW->scrActions["toolsInsertPolygon"]->setMenu(insertPolygonButtonMenu);
65 	QToolButton* tb2 = dynamic_cast<QToolButton*>(this->widgetForAction(m_ScMW->scrActions["toolsInsertPolygon"]));
66 	tb2->setPopupMode(QToolButton::DelayedPopup);
67 
68 	this->addAction(m_ScMW->scrActions["toolsInsertArc"]);
69 	this->addAction(m_ScMW->scrActions["toolsInsertSpiral"]);
70 	this->addAction(m_ScMW->scrActions["toolsInsertLine"]);
71 	this->addAction(m_ScMW->scrActions["toolsInsertBezier"]);
72 	this->addAction(m_ScMW->scrActions["toolsInsertFreehandLine"]);
73 
74 	propWidget = new QWidget();
75 	group1Layout = new QGridLayout( propWidget );
76 	group1Layout->setSpacing(3);
77 	group1Layout->setContentsMargins(3, 3, 3, 3);
78 	group1Layout->setAlignment( Qt::AlignTop );
79 	Angle = new ScrSpinBox( -180, 180, propWidget, 6 );
80 	Angle->setValue( 0 );
81 	AngleTxt = new QLabel( tr("Angle:"), propWidget );
82 	group1Layout->addWidget( Angle, 0, 1 );
83 	group1Layout->addWidget( AngleTxt, 0 , 0 );
84 	PWidth = new ScrSpinBox( 0, 100, propWidget, 0 );
85 	PWidth->setValue( 10 );
86 	PWidthTxt = new QLabel( tr("Width:"), propWidget );
87 	group1Layout->addWidget( PWidth, 1, 1 );
88 	group1Layout->addWidget( PWidthTxt, 1 , 0 );
89 	calPop = new QMenu();
90 	calValAct = new QWidgetAction(this);
91 	calValAct->setDefaultWidget(propWidget);
92 	calPop->addAction(calValAct);
93 	this->addAction(m_ScMW->scrActions["toolsInsertCalligraphicLine"]);
94 	m_ScMW->scrActions["toolsInsertCalligraphicLine"]->setMenu(calPop);
95 	QToolButton* tb3 = dynamic_cast<QToolButton*>(this->widgetForAction(m_ScMW->scrActions["toolsInsertCalligraphicLine"]));
96 	tb3->setPopupMode(QToolButton::DelayedPopup);
97 
98 	this->addAction(m_ScMW->scrActions["toolsRotate"]);
99 	this->addAction(m_ScMW->scrActions["toolsZoom"]);
100 	this->addAction(m_ScMW->scrActions["toolsEditContents"]);
101 	this->addAction(m_ScMW->scrActions["toolsEditWithStoryEditor"]);
102 	this->addAction(m_ScMW->scrActions["toolsLinkTextFrame"]);
103 	this->addAction(m_ScMW->scrActions["toolsUnlinkTextFrame"]);
104 	this->addAction(m_ScMW->scrActions["toolsMeasurements"]);
105 	this->addAction(m_ScMW->scrActions["toolsCopyProperties"]);
106 	this->addAction(m_ScMW->scrActions["toolsEyeDropper"]);
107 
108 	languageChange();
109 	connect(autoFormButtonGroup, SIGNAL(FormSel(int, int, qreal *)), this, SLOT(SelShape(int, int, qreal *)));
110 	connect(Angle, SIGNAL(valueChanged(double)), this, SLOT(newCalValues()));
111 	connect(PWidth, SIGNAL(valueChanged(double)), this, SLOT(newCalValues()));
112 }
113 
~ModeToolBar()114 ModeToolBar::~ModeToolBar()
115 {
116 	delete calValAct;
117 	delete calPop;
118 }
119 
newCalValues()120 void ModeToolBar::newCalValues()
121 {
122 	m_ScMW->doc->itemToolPrefs().calligraphicPenAngle = Angle->value();
123 	m_ScMW->doc->itemToolPrefs().calligraphicPenWidth = PWidth->value();
124 }
125 
GetPolyProps()126 void ModeToolBar::GetPolyProps()
127 {
128 	PolygonProps* dia = new PolygonProps(m_ScMW, m_ScMW->doc->itemToolPrefs().polyCorners, m_ScMW->doc->itemToolPrefs().polyFactor, m_ScMW->doc->itemToolPrefs().polyUseFactor, m_ScMW->doc->itemToolPrefs().polyRotation, m_ScMW->doc->itemToolPrefs().polyCurvature, m_ScMW->doc->itemToolPrefs().polyInnerRot, m_ScMW->doc->itemToolPrefs().polyOuterCurvature);
129 	if (dia->exec())
130 	{
131 		dia->getValues(&m_ScMW->doc->itemToolPrefs().polyCorners, &m_ScMW->doc->itemToolPrefs().polyFactor, &m_ScMW->doc->itemToolPrefs().polyUseFactor, &m_ScMW->doc->itemToolPrefs().polyRotation, &m_ScMW->doc->itemToolPrefs().polyCurvature, &m_ScMW->doc->itemToolPrefs().polyInnerRot, &m_ScMW->doc->itemToolPrefs().polyOuterCurvature);
132 		m_ScMW->scrActions["toolsInsertPolygon"]->trigger();
133 	}
134 	delete dia;
135 }
136 
SelShape(int s,int c,qreal * vals)137 void ModeToolBar::SelShape(int s, int c, qreal *vals)
138 {
139 	m_ScMW->scrActions["toolsInsertShape"]->setIcon(QIcon(autoFormButtonGroup->getIconPixmap(s,16)));
140 	SubMode = s;
141 	ValCount = c;
142 	ShapeVals = vals;
143 	m_ScMW->scrActions["toolsInsertShape"]->setChecked(false);
144 	m_ScMW->scrActions["toolsInsertShape"]->setChecked(true);
145 }
146 
changeEvent(QEvent * e)147 void ModeToolBar::changeEvent(QEvent *e)
148 {
149 	if (e->type() == QEvent::LanguageChange)
150 	{
151 		languageChange();
152 	}
153 	else
154 		QWidget::changeEvent(e);
155 }
156 
setDoc(ScribusDoc * doc)157 void ModeToolBar::setDoc(ScribusDoc* doc)
158 {
159 	Angle->setValue(doc->itemToolPrefs().calligraphicPenAngle);
160 	PWidth->setValue(doc->itemToolPrefs().calligraphicPenWidth);
161 }
162 
languageChange()163 void ModeToolBar::languageChange()
164 {
165 	AngleTxt->setText(tr("Angle:"));
166 	PWidthTxt->setText(tr("Width:"));
167 	idInsertPolygonButtonMenu->setText( tr("Properties..."));
168 	ScToolBar::languageChange();
169 }
170