Paste text from clipboard.
This commit is contained in:
+13
-3
@@ -28,7 +28,9 @@
|
|||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
#include "LabelModelObject.h"
|
#include "LabelModelObject.h"
|
||||||
|
#include "LabelModelTextObject.h"
|
||||||
#include "Region.h"
|
#include "Region.h"
|
||||||
|
#include "Size.h"
|
||||||
#include "XmlLabelCreator.h"
|
#include "XmlLabelCreator.h"
|
||||||
#include "XmlLabelParser.h"
|
#include "XmlLabelParser.h"
|
||||||
|
|
||||||
@@ -1370,11 +1372,11 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
else if ( mimeData->hasImage() )
|
else if ( mimeData->hasImage() )
|
||||||
{
|
{
|
||||||
// TODO: return true
|
return true;
|
||||||
}
|
}
|
||||||
else if ( mimeData->hasText() )
|
else if ( mimeData->hasText() )
|
||||||
{
|
{
|
||||||
// TODO: return true
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1390,6 +1392,7 @@ namespace glabels
|
|||||||
|
|
||||||
if ( mimeData->hasFormat( MIME_TYPE ) )
|
if ( mimeData->hasFormat( MIME_TYPE ) )
|
||||||
{
|
{
|
||||||
|
// Native objects
|
||||||
QByteArray buffer = mimeData->data( MIME_TYPE );
|
QByteArray buffer = mimeData->data( MIME_TYPE );
|
||||||
QList <LabelModelObject*> objects = XmlLabelParser::deserializeObjects( buffer );
|
QList <LabelModelObject*> objects = XmlLabelParser::deserializeObjects( buffer );
|
||||||
|
|
||||||
@@ -1402,11 +1405,18 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
else if ( mimeData->hasImage() )
|
else if ( mimeData->hasImage() )
|
||||||
{
|
{
|
||||||
|
// Create object from clipboard image
|
||||||
// TODO: create an image object from image
|
// TODO: create an image object from image
|
||||||
}
|
}
|
||||||
else if ( mimeData->hasText() )
|
else if ( mimeData->hasText() )
|
||||||
{
|
{
|
||||||
// TODO: create a text object from text
|
// Create object from clipboard text
|
||||||
|
LabelModelTextObject* object = new LabelModelTextObject();
|
||||||
|
object->setText( mimeData->text() );
|
||||||
|
object->setSize( object->naturalSize() );
|
||||||
|
object->setPosition( (w()-object->w())/2.0, (h()-object->h())/2.0 );
|
||||||
|
addObject( object );
|
||||||
|
selectObject( object );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,9 +120,9 @@ namespace glabels
|
|||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Image originalSize Property Getter (assumes 72 DPI, i.e. 1pixel == 1pt)
|
/// naturalSize Property Getter (assumes 72 DPI, i.e. 1pixel == 1pt)
|
||||||
///
|
///
|
||||||
Size LabelModelImageObject::originalSize() const
|
Size LabelModelImageObject::naturalSize() const
|
||||||
{
|
{
|
||||||
Size size( Distance::pt(72), Distance::pt(72) );
|
Size size( Distance::pt(72), Distance::pt(72) );
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ namespace glabels
|
|||||||
virtual void setFilenameNode( const TextNode& value );
|
virtual void setFilenameNode( const TextNode& value );
|
||||||
|
|
||||||
//
|
//
|
||||||
// Image Property: originalSize
|
// Property: naturalSize
|
||||||
//
|
//
|
||||||
virtual Size originalSize() const;
|
virtual Size naturalSize() const;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -370,6 +370,16 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Virtual Natural Size Property Default Getter
|
||||||
|
/// (Overridden by concrete class)
|
||||||
|
///
|
||||||
|
Size LabelModelObject::naturalSize() const
|
||||||
|
{
|
||||||
|
return Size( Distance::pt(0), Distance::pt(0) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Virtual Text Property Default Getter
|
/// Virtual Text Property Default Getter
|
||||||
/// (Overridden by concrete class)
|
/// (Overridden by concrete class)
|
||||||
@@ -590,16 +600,6 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Virtual Original Size Property Default Getter
|
|
||||||
/// (Overridden by concrete class)
|
|
||||||
///
|
|
||||||
Size LabelModelObject::originalSize() const
|
|
||||||
{
|
|
||||||
return Size( Distance::pt(0), Distance::pt(0) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Virtual Line Width Property Default Getter
|
/// Virtual Line Width Property Default Getter
|
||||||
/// (Overridden by concrete class)
|
/// (Overridden by concrete class)
|
||||||
|
|||||||
@@ -163,6 +163,12 @@ namespace glabels
|
|||||||
void setShadowColorNode( const ColorNode& value );
|
void setShadowColorNode( const ColorNode& value );
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Natural Size Property (read-only)
|
||||||
|
//
|
||||||
|
virtual Size naturalSize() const;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
// Text Properties Virtual Interface
|
// Text Properties Virtual Interface
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
@@ -247,11 +253,6 @@ namespace glabels
|
|||||||
virtual TextNode filenameNode() const;
|
virtual TextNode filenameNode() const;
|
||||||
virtual void setFilenameNode( const TextNode &value );
|
virtual void setFilenameNode( const TextNode &value );
|
||||||
|
|
||||||
//
|
|
||||||
// Virtual Image Property: originalSize (read-only)
|
|
||||||
//
|
|
||||||
virtual Size originalSize() const;
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
// Shape Properties Virtual Interface
|
// Shape Properties Virtual Interface
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
#include "Size.h"
|
||||||
|
|
||||||
|
|
||||||
namespace glabels
|
namespace glabels
|
||||||
{
|
{
|
||||||
@@ -86,6 +88,8 @@ namespace glabels
|
|||||||
mTextHAlign = object->mTextHAlign;
|
mTextHAlign = object->mTextHAlign;
|
||||||
mTextVAlign = object->mTextVAlign;
|
mTextVAlign = object->mTextVAlign;
|
||||||
mTextLineSpacing = object->mTextLineSpacing;
|
mTextLineSpacing = object->mTextLineSpacing;
|
||||||
|
|
||||||
|
update(); // Initialize cached editor layouts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -343,6 +347,55 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// NaturalSize Property Getter
|
||||||
|
///
|
||||||
|
Size LabelModelTextObject::naturalSize() const
|
||||||
|
{
|
||||||
|
QFont font;
|
||||||
|
font.setFamily( mFontFamily );
|
||||||
|
font.setPointSizeF( mFontSize );
|
||||||
|
font.setWeight( mFontWeight );
|
||||||
|
font.setItalic( mFontItalicFlag );
|
||||||
|
font.setUnderline( mFontUnderlineFlag );
|
||||||
|
|
||||||
|
QTextOption textOption;
|
||||||
|
textOption.setAlignment( mTextHAlign );
|
||||||
|
textOption.setWrapMode( QTextOption::WordWrap );
|
||||||
|
|
||||||
|
QFontMetricsF fontMetrics( font );
|
||||||
|
double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
|
||||||
|
|
||||||
|
QString displayText = mText.isEmpty() ? tr("Text") : mText;
|
||||||
|
QTextDocument document( displayText );
|
||||||
|
|
||||||
|
// Do layouts
|
||||||
|
double x = 0;
|
||||||
|
double y = 0;
|
||||||
|
QRectF boundingRect;
|
||||||
|
for ( int i = 0; i < document.blockCount(); i++ )
|
||||||
|
{
|
||||||
|
QTextLayout* layout = new QTextLayout( document.findBlockByNumber(i).text() );
|
||||||
|
|
||||||
|
layout->setFont( font );
|
||||||
|
layout->setTextOption( textOption );
|
||||||
|
layout->setCacheEnabled(true);
|
||||||
|
|
||||||
|
layout->beginLayout();
|
||||||
|
for ( QTextLine l = layout->createLine(); l.isValid(); l = layout->createLine() )
|
||||||
|
{
|
||||||
|
l.setPosition( QPointF( x, y ) );
|
||||||
|
y += dy;
|
||||||
|
}
|
||||||
|
layout->endLayout();
|
||||||
|
|
||||||
|
boundingRect = layout->boundingRect().united( boundingRect );
|
||||||
|
}
|
||||||
|
|
||||||
|
return Size( boundingRect.width() + 2*marginPts, boundingRect.height() + 2*marginPts );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Can Text Capability Implementation
|
/// Can Text Capability Implementation
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ namespace glabels
|
|||||||
virtual void setTextLineSpacing( double value );
|
virtual void setTextLineSpacing( double value );
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Property: naturalSize
|
||||||
|
//
|
||||||
|
virtual Size naturalSize() const;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
// Capability Implementations
|
// Capability Implementations
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ namespace glabels
|
|||||||
sizeWSpin->setValue( mObject->w().inUnits(mUnits) );
|
sizeWSpin->setValue( mObject->w().inUnits(mUnits) );
|
||||||
sizeHSpin->setValue( mObject->h().inUnits(mUnits) );
|
sizeHSpin->setValue( mObject->h().inUnits(mUnits) );
|
||||||
|
|
||||||
Size originalSize = mObject->originalSize();
|
Size originalSize = mObject->naturalSize();
|
||||||
QString originalSizeString = QString( "%1: %2 x %3 %4" )
|
QString originalSizeString = QString( "%1: %2 x %3 %4" )
|
||||||
.arg( tr("Original size") )
|
.arg( tr("Original size") )
|
||||||
.arg( originalSize.w().inUnits(mUnits), 0, 'f', mSpinDigits )
|
.arg( originalSize.w().inUnits(mUnits), 0, 'f', mSpinDigits )
|
||||||
@@ -662,7 +662,7 @@ namespace glabels
|
|||||||
|
|
||||||
void ObjectEditor::onResetImageSize()
|
void ObjectEditor::onResetImageSize()
|
||||||
{
|
{
|
||||||
mObject->setSize( mObject->originalSize() );
|
mObject->setSize( mObject->naturalSize() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user