File indexing completed on 2024-05-12 16:33:19

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007,2011 Jan Hambrecht <jaham@gmx.net>
0003  * Copyright (C) 2008 Rob Buis <buis@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #include "ArtisticTextShapeConfigWidget.h"
0022 #include "ArtisticTextTool.h"
0023 #include "ArtisticTextToolSelection.h"
0024 #include "ArtisticTextShape.h"
0025 
0026 #include <QAction>
0027 
0028 ArtisticTextShapeConfigWidget::ArtisticTextShapeConfigWidget(ArtisticTextTool *textTool)
0029     : m_textTool(textTool)
0030 {
0031     Q_ASSERT(m_textTool);
0032 
0033     widget.setupUi( this );
0034 
0035     widget.bold->setDefaultAction(textTool->action("artistictext_font_bold"));
0036     widget.italic->setDefaultAction(textTool->action("artistictext_font_italic"));
0037     widget.superScript->setDefaultAction(textTool->action("artistictext_superscript"));
0038     widget.subScript->setDefaultAction(textTool->action("artistictext_subscript"));
0039     widget.anchorStart->setDefaultAction(textTool->action("artistictext_anchor_start"));
0040     widget.anchorMiddle->setDefaultAction(textTool->action("artistictext_anchor_middle"));
0041     widget.anchorEnd->setDefaultAction(textTool->action("artistictext_anchor_end"));
0042     widget.fontSize->setRange( 2, 1000 );
0043 
0044     connect(widget.fontFamily, SIGNAL(currentFontChanged(QFont)), this, SIGNAL(fontFamilyChanged(QFont)));
0045     connect(widget.fontSize, SIGNAL(valueChanged(int)), this, SIGNAL(fontSizeChanged(int)));
0046 }
0047 
0048 void ArtisticTextShapeConfigWidget::blockChildSignals( bool block )
0049 {
0050     widget.fontFamily->blockSignals( block );
0051     widget.fontSize->blockSignals( block );
0052 }
0053 
0054 void ArtisticTextShapeConfigWidget::updateWidget()
0055 {
0056     ArtisticTextToolSelection *selection = dynamic_cast<ArtisticTextToolSelection*>(m_textTool->selection());
0057     if (!selection)
0058         return;
0059 
0060     ArtisticTextShape *currentText = selection->selectedShape();
0061     if (!currentText)
0062         return;
0063 
0064     blockChildSignals( true );
0065 
0066     QFont font = currentText->fontAt(m_textTool->textCursor());
0067 
0068     widget.fontSize->setValue( font.pointSize() );
0069     font.setPointSize( 8 );
0070     widget.fontFamily->setCurrentFont( font );
0071 
0072     blockChildSignals( false );
0073 }