An optimization against dnd text fixes Sankore 408

preferencesAboutTextFull
Ivan Ilin 13 years ago
parent 7670a812cc
commit 4816619b68
  1. 33
      src/board/UBBoardView.cpp
  2. 2
      src/board/UBBoardView.h
  3. 123
      src/domain/UBGraphicsTextItemDelegate.cpp
  4. 5
      src/domain/UBGraphicsTextItemDelegate.h

@ -72,6 +72,7 @@ UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent)
, mController (pController)
, mIsCreatingTextZone (false)
, mIsCreatingSceneGrabZone (false)
, mOkOnWidget(false)
{
init ();
@ -738,16 +739,27 @@ void UBBoardView::dragMoveEvent (QDragMoveEvent *event)
QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y());
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos);
if (graphicsWidget && graphicsWidget->acceptDrops()){
if (isDropableData(event->mimeData())) {
if (graphicsWidget) {
if (graphicsWidget->acceptDrops()) {
if (!mOkOnWidget) {
if (!isDropableData(event->mimeData())) {
mOkOnWidget = false;
event->ignore();
return;
} else {
mOkOnWidget = true;
}
}
QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint());
QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers());
QApplication::sendEvent(graphicsWidget->widgetWebView(),&newEvent);
} else {
mOkOnWidget = false;
event->ignore();
}
} else {
} else {
event->acceptProposedAction();
mOkOnWidget = false;
}
}
@ -804,6 +816,9 @@ QString UBBoardView::fileExtention(const QString &filename)
}
QString UBBoardView::typeForExtention(const QString &extention)
{
if (extention.isEmpty())
return QString();
QString result = QString();
if (audioExtentions.contains(extention)) {
@ -812,24 +827,26 @@ QString UBBoardView::typeForExtention(const QString &extention)
result = videoAlias;
} else if (imageExtentions.contains(extention)) {
result = imageAlias;
} else if (htmlExtentions.contains(extention)) {
result = htmlAlias;
// } else if (htmlExtentions.contains(extention)) {
// result = htmlAlias;
}
return result;
}
bool UBBoardView::isDropableData(const QMimeData *pMimeData)
{
if (pMimeData->hasUrls())
if (!typeForExtention(fileExtention(pMimeData->urls().at(0).toLocalFile())).isNull())
if (pMimeData->hasUrls()) {
if (!typeForExtention(fileExtention(pMimeData->urls().at(0).toLocalFile())).isNull()) {
return true;
}
}
return false;
}
void UBBoardView::dropEvent (QDropEvent *event)
{
qDebug() << event->source();
mOkOnWidget = false;
QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y());
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos);

@ -116,6 +116,8 @@ class UBBoardView : public QGraphicsView
bool isAbsurdPoint(QPoint point);
bool mVirtualKeyboardActive;
bool mOkOnWidget;
QString typeForExtention(const QString &extention);
QString fileExtention(const QString &filename);

@ -35,6 +35,7 @@ const int UBGraphicsTextItemDelegate::sMinPointSize = 8;
UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject * parent)
: UBGraphicsItemDelegate(pDelegated,0, parent, true)
, mLastFontPixelSize(-1)
, delta(5)
{
delegated()->setData(UBGraphicsItemData::ItemEditable, QVariant(true));
delegated()->setPlainText("");
@ -231,82 +232,12 @@ void UBGraphicsTextItemDelegate::pickColor()
void UBGraphicsTextItemDelegate::decreaseSize()
{
QTextCursor cursor = delegated()->textCursor();
QTextCharFormat textFormat;
QFont curFont = cursor.charFormat().font();
int pointSize = curFont.pointSize();
pointSize -= 5;
// QFontInfo fi(delegated()->font());
// int pixelSize = fi.pixelSize();
// if (-1 == mLastFontPixelSize)
// mLastFontPixelSize = pixelSize;
// int newPixelSize = sMinPixelSize;
// while (newPixelSize * 1.5 < pixelSize)
// newPixelSize *= 1.5;
// if (newPixelSize < mLastFontPixelSize && mLastFontPixelSize < pixelSize)
// newPixelSize = mLastFontPixelSize;
// if (pixelSize > newPixelSize)
// {
// QFont font = delegated()->font();
// font.setPixelSize(newPixelSize);
// delegated()->setFont(font);
// UBSettings::settings()->setFontPixelSize(newPixelSize);
// delegated()->document()->adjustSize();
// delegated()->contentsChanged();dddd
// }
curFont.setPointSize(pointSize);
textFormat.setFont(curFont);
cursor.mergeCharFormat(textFormat);
delegated()->setTextCursor(cursor);
UBSettings::settings()->setFontPixelSize(curFont.pixelSize());
UBSettings::settings()->setFontPointSize(pointSize);
delegated()->document()->adjustSize();
delegated()->setFont(curFont);
ChangeTextSize(-delta);
}
void UBGraphicsTextItemDelegate::increaseSize()
{
QTextCursor cursor = delegated()->textCursor();
QTextCharFormat textFormat;
QFont curFont = cursor.charFormat().font();
int pointSize = curFont.pointSize();
pointSize += 5;
// QFontInfo fi(cursor.charFormat().font());
// int pixelSize = fi.pixelSize();
// if (-1 == mLastFontPixelSize)
// mLastFontPixelSize = pixelSize;
// int newPixelSize = sMinPixelSize;
// while (newPixelSize <= pixelSize)
// newPixelSize *= 1.5;
// if (pixelSize < mLastFontPixelSize && mLastFontPixelSize < newPixelSize)
// newPixelSize = mLastFontPixelSize;
curFont.setPointSize(pointSize);
textFormat.setFont(curFont);
cursor.mergeCharFormat(textFormat);
delegated()->setTextCursor(cursor);
// UBSettings::settings()->setFontPixelSize(curFont.pixelSize());
UBSettings::settings()->setFontPointSize(pointSize);
delegated()->document()->adjustSize();
delegated()->setFont(curFont);
// delegated()->contentsChanged();
ChangeTextSize(delta);
}
UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated()
@ -349,3 +280,51 @@ void UBGraphicsTextItemDelegate::positionHandles()
UBGraphicsItemDelegate::positionHandles();
setEditable(isEditable());
}
void UBGraphicsTextItemDelegate::ChangeTextSize(int delta)
{
if (0 == delta)
return;
QTextCursor cursor = delegated()->textCursor();
QTextCharFormat textFormat;
int anchorPos = cursor.anchor();
int cursorPos = cursor.position();
if (0 == anchorPos-cursorPos)
{
cursor.setPosition (0, QTextCursor::MoveAnchor);
cursor.setPosition (cursor.document()->characterCount()-1, QTextCursor::KeepAnchor);
}
int startPos = qMin(cursor.anchor(), cursor.position());
int endPos = qMax(cursor.anchor(), cursor.position());
for (int i = startPos; i < endPos ; i++)
{
// selecting single symbol
cursor.setPosition (i, QTextCursor::MoveAnchor);
cursor.setPosition (i+1, QTextCursor::KeepAnchor);
//setting new parameners
QFont curFont = cursor.charFormat().font();
int pointSize = curFont.pointSize() + delta;
curFont.setPointSize(pointSize);
textFormat.setFont(curFont);
cursor.mergeCharFormat(textFormat);
delegated()->setTextCursor(cursor);
UBSettings::settings()->setFontPointSize(pointSize);
delegated()->document()->adjustSize();
delegated()->setFont(curFont);
}
//returning initial selection
cursor.setPosition (anchorPos, QTextCursor::MoveAnchor);
cursor.setPosition (cursorPos, QTextCursor::KeepAnchor);
delegated()->setTextCursor(cursor);
}

@ -61,6 +61,8 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
private:
void customize(QFontDialog &fontDialog);
void ChangeTextSize(int delta);
QFont createDefaultFont();
QAction *mEditableAction;
@ -72,6 +74,9 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
void decreaseSize();
void increaseSize();
private:
const int delta;
};
#endif /* UBGRAPHICSTEXTITEMDELEGATE_H_ */

Loading…
Cancel
Save