[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra/kotext-inlinecommand-rempt] words/part: Anchor newly
From: Silvio Heinrich <plassy () web ! de>
Date: 2012-01-05 17:01:37
Message-ID: 20120105170137.17BA1A60A6 () git ! kde ! org
[Download RAW message or body]
Git commit a936b1ceb009c0802b1e3f9cd664aa8a30dfaf0b by Silvio Heinrich.
Committed on 05/01/2012 at 18:00.
Pushed by heinrich into branch 'kotext-inlinecommand-rempt'.
Anchor newly added images to page per default.
M +33 -149 words/part/KWView.cpp
http://commits.kde.org/calligra/a936b1ceb009c0802b1e3f9cd664aa8a30dfaf0b
diff --git a/words/part/KWView.cpp b/words/part/KWView.cpp
index 99d15c3..0ed16b2 100644
--- a/words/part/KWView.cpp
+++ b/words/part/KWView.cpp
@@ -1293,15 +1293,21 @@ void KWView::loadingCompleted()
void KWView::addImages(const QList<QImage> &imageList, const QPoint &insertAt)
{
if (!m_canvas) {
- // now canvas because we're not on the desktop?
+ // no canvas because we're not on the desktop?
return;
}
- // get position from event and convert to document coordinates
- QPointF pos = m_canvas->viewConverter()->viewToDocument(insertAt)
- + m_canvas->documentOffset()- m_canvas->documentOrigin();
+ QPointF pos(0, 0);
+
+ /* TODO: find out how to convert the position correctly
+ // get position from event and convert to document coordinates
+ QPointF pos = m_canvas->viewConverter()->viewToDocument(insertAt) +
+ m_canvas->documentOffset() - m_canvas->documentOrigin();
+ //*/
+
// create a factory
KoShapeFactoryBase *factory = \
KoShapeRegistry::instance()->value("PictureShape"); +
if (!factory) {
kWarning(30003) << "No picture shape found, cannot drop images.";
return;
@@ -1310,6 +1316,7 @@ void KWView::addImages(const QList<QImage> &imageList, const \
QPoint &insertAt) // get the textshape at this point
QList<KoShape*> possibleTextShapes = \
canvasBase()->shapeManager()->shapesAt(QRectF(pos.x() - 10, pos.y() -10, 20, 20)); \
KoTextShapeData *textShapeData = 0; +
foreach (KoShape* shape, possibleTextShapes) {
KoShapeUserData *userData = shape->userData();
if ((textShapeData = dynamic_cast<KoTextShapeData*>(userData))) {
@@ -1318,36 +1325,9 @@ void KWView::addImages(const QList<QImage> &imageList, const \
QPoint &insertAt) }
}
- KDialog dlg;
- dlg.setCaption(i18n("Insert Image Options"));
- QWidget *page = new QWidget(&dlg);
- dlg.setMainWidget(page);
- Ui_KWInsertImage uiInsertImage;
- uiInsertImage.setupUi(page);
-
- if (textShapeData) {
- // ask the user what kind of anchoring and run-around to use
- if (dlg.exec() == QDialog::Rejected) {
- return;
- }
- }
- else {
- // ask the user what kind of run-around to use
- uiInsertImage.grpAnchor->setVisible(false);
- uiInsertImage.grpHAlign->setVisible(false);
- uiInsertImage.grpVAlign->setVisible(false);
-
- if (dlg.exec() == KDialog::QDialog::Rejected) {
- return;
- }
- }
-
foreach(const QImage image, imageList) {
-
KoProperties params;
- QVariant v;
- v.setValue<QImage>(image);
- params.setProperty("qimage", v);
+ params.setProperty("qimage", image);
KoShape *shape = factory->createShape(¶ms, \
kwdocument()->resourceManager());
@@ -1355,9 +1335,8 @@ void KWView::addImages(const QList<QImage> &imageList, const \
QPoint &insertAt) // hard-coded constants.
qreal pageWidth = currentPage().width();
qreal pageHeight = currentPage().height();
- if (shape->size().width() > pageWidth * 0.8 ||
- shape->size().height() > pageHeight)
- {
+
+ if (shape->size().width() > (pageWidth * 0.8) || shape->size().height() > \
pageHeight) { QSizeF sz = shape->size();
sz.scale(QSizeF(pageWidth * 0.6, pageHeight *.6), Qt::KeepAspectRatio);
shape->setSize(sz);
@@ -1368,121 +1347,26 @@ void KWView::addImages(const QList<QImage> &imageList, const \
QPoint &insertAt) return;
}
- // Set the wraparound
- if (uiInsertImage.noRunaround->isChecked()) {
- shape->setTextRunAroundSide(KoShape::NoRunAround);
- }
- else if (uiInsertImage.left->isChecked()) {
- shape->setTextRunAroundSide(KoShape::LeftRunAroundSide);
- }
- else if (uiInsertImage.right->isChecked()) {
- shape->setTextRunAroundSide(KoShape::RightRunAroundSide);
- }
- else if (uiInsertImage.longest->isChecked()) {
- shape->setTextRunAroundSide(KoShape::BiggestRunAroundSide);
- }
- else if (uiInsertImage.both->isChecked()) {
- shape->setTextRunAroundSide(KoShape::BothRunAroundSide);
- }
- else if (uiInsertImage.enough->isChecked()) {
- shape->setTextRunAroundSide(KoShape::EnoughRunAroundSide);
- double threshold = uiInsertImage.threshold->value();
- shape->setTextRunAroundThreshold(threshold);
- }
-
- KoTextAnchor *anchor = 0;
- double distance = uiInsertImage.distance->value();
- shape->setTextRunAroundDistance(distance);
+ shape->setTextRunAroundSide(KoShape::BothRunAroundSide);
- // only if we have a text shape, we will anchor to the text inside.
- if (textShapeData) {
-
- // Create the anchor
- QTextDocument *qdoc = textShapeData->document();
- anchor = new KoTextAnchor(shape);
-
- // anchor
- // XXX: What about: HFrame, HFrameContent, HFrameEndMargin, \
HFrameStartMargin?
- anchor->setAnchorType(KoTextAnchor::AnchorToCharacter);
- if (uiInsertImage.rAnchorPage->isChecked()) {
- // XXX: or: VPageContent?
- anchor->setVerticalRel(KoTextAnchor::VPage);
- // XXX: or: HPageContent or HPageStartMargin or HPageEndMargin?
- anchor->setHorizontalRel(KoTextAnchor::HPage);
-
- }
- else if (uiInsertImage.rAnchorParagraph->isChecked()) {
- // XXX: or: VParagraphContent?
- anchor->setVerticalRel(KoTextAnchor::VParagraph);
- // XXX: or HParagraphContent, HParagraphEndMargin, \
HParagraphStartMargin?
- anchor->setHorizontalRel(KoTextAnchor::HParagraph);
-
- }
- else if (uiInsertImage.rAnchorToCharacter->isChecked()) {
- // XXX: or VBaseline, VLine?
- anchor->setVerticalRel(KoTextAnchor::VChar);
- anchor->setHorizontalRel(KoTextAnchor::HChar);
-
- }
- else if (uiInsertImage.rAnchorAsCharacter->isChecked()) {
- anchor->setVerticalRel(KoTextAnchor::VBaseline);
- anchor->setHorizontalRel(KoTextAnchor::HChar);
- anchor->setAnchorType(KoTextAnchor::AnchorAsCharacter);
- }
-
- // horizontal alignment
- // XXX: what about HFromInside, HFromLeft, HInside, HOutside?
- if (uiInsertImage.rAlignLeft->isChecked()) {
- anchor->setHorizontalPos(KoTextAnchor::HLeft);
- }
- else if (uiInsertImage.rAlignCenter->isChecked()) {
- anchor->setHorizontalPos(KoTextAnchor::HCenter);
- }
- else if (uiInsertImage.rAlignRight->isChecked()) {
- anchor->setHorizontalPos(KoTextAnchor::HRight);
- }
-
- // vertical alignment
- if (uiInsertImage.rAlignTop->isChecked()) {
- // XXX: or VFromTop?
- anchor->setVerticalPos(KoTextAnchor::VTop);
- }
- else if (uiInsertImage.rAlignMiddle->isChecked()) {
- anchor->setVerticalPos(KoTextAnchor::VMiddle);
- }
- else if (uiInsertImage.rAlignBottom->isChecked()) {
- anchor->setVerticalPos(KoTextAnchor::VBottom);
- }
-
- anchor->setOffset(QPointF(0, -shape->size().height()));
- // insert the anchor into the text document
- KoTextEditor editor(qdoc);
-
- // create the master command
- KUndo2Command *macro = new KUndo2Command(i18nc("(qtundo-format)", \
"Create shape"));
- editor.insertInlineObject(anchor, macro);
-
- // create the undo step.
- new KoShapeCreateCommand(kwdocument(), shape, macro);
- KoSelection *selection = m_canvas->shapeManager()->selection();
- selection->deselectAll();
- selection->select(shape);
- m_canvas->addCommand(macro);
-
- kwdocument()->getFrameOfShape(shape)->setAnchor(anchor);
- }
- else {
- shape->setPosition(pos);
- pos += QPointF(25,25); // increase the position for each shape we insert \
so the
- // user can see them all.
-
- // create the undo step.
- KWShapeCreateCommand *cmd = new KWShapeCreateCommand(kwdocument(), \
shape, anchor);
- KoSelection *selection = m_canvas->shapeManager()->selection();
- selection->deselectAll();
- selection->select(shape);
- m_canvas->addCommand(cmd);
- }
+ QTextDocument *qdoc = textShapeData ? textShapeData->document() : 0;
+ KoTextAnchor *anchor = new KoTextAnchor(shape);
+ anchor->setAnchorType(KoTextAnchor::AnchorPage);
+ anchor->setHorizontalPos(KoTextAnchor::HFromLeft);
+ anchor->setVerticalPos(KoTextAnchor::VFromTop);
+ anchor->setHorizontalRel(KoTextAnchor::HPage);
+ anchor->setVerticalRel(KoTextAnchor::VPage);
+ shape->setPosition(pos);
+
+ pos += QPointF(25,25); // increase the position for each shape we insert so \
the + // user can see them all.
+
+ // create the undo step.
+ KWShapeCreateCommand *cmd = new KWShapeCreateCommand(kwdocument(), shape, \
anchor); + KoSelection *selection = m_canvas->shapeManager()->selection();
+ selection->deselectAll();
+ selection->select(shape);
+ m_canvas->addCommand(cmd);
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic