Fixing font problem on Windows.

Calc start label scale based on start font size and minimal visible font size.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-28 13:02:51 +03:00
parent 72dde072af
commit 104a491a67
5 changed files with 31 additions and 20 deletions

View File

@ -36,6 +36,7 @@
static const qreal defPointRadiusPixel = (2./*mm*/ / 25.4) * PrintDPI; static const qreal defPointRadiusPixel = (2./*mm*/ / 25.4) * PrintDPI;
const qreal widthMainLine = (1.2/*mm*/ / 25.4) * PrintDPI; const qreal widthMainLine = (1.2/*mm*/ / 25.4) * PrintDPI;
const qreal widthHairLine = widthMainLine/3.0; const qreal widthHairLine = widthMainLine/3.0;
const qreal minVisibleFontSize = 5;
qreal SceneScale(QGraphicsScene *scene) qreal SceneScale(QGraphicsScene *scene)
{ {

View File

@ -33,6 +33,7 @@
extern const qreal widthMainLine; extern const qreal widthMainLine;
extern const qreal widthHairLine; extern const qreal widthHairLine;
extern const qreal minVisibleFontSize;
class QGraphicsScene; class QGraphicsScene;
class QGraphicsItem; class QGraphicsItem;

View File

@ -54,19 +54,12 @@
* @param parent parent object. * @param parent parent object.
*/ */
VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent) VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent)
:QGraphicsSimpleTextItem(parent), m_fontSize(0), selectionType(SelectionType::ByMouseRelease), : QGraphicsSimpleTextItem(parent),
m_oldScale(VMainGraphicsView::MinScale()) m_fontSize(0),
selectionType(SelectionType::ByMouseRelease),
m_oldScale(1)
{ {
this->setFlag(QGraphicsItem::ItemIsMovable, true); Init();
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
this->setAcceptHoverEvents(true);
QFont font = this->font();
font.setPointSize(font.pointSize()+20);
m_fontSize = font.pointSize();
this->setFont(font);
setScale(m_oldScale);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -76,14 +69,12 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent)
* @param parent parent object. * @param parent parent object.
*/ */
VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent ) VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent )
:QGraphicsSimpleTextItem(text, parent), m_fontSize(0), selectionType(SelectionType::ByMouseRelease), : QGraphicsSimpleTextItem(text, parent),
m_oldScale(VMainGraphicsView::MinScale()) m_fontSize(0),
selectionType(SelectionType::ByMouseRelease),
m_oldScale(1)
{ {
this->setFlag(QGraphicsItem::ItemIsMovable, true); Init();
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setAcceptHoverEvents(true);
setScale(m_oldScale);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -319,3 +310,19 @@ void VGraphicsSimpleTextItem::keyReleaseEvent(QKeyEvent *event)
} }
QGraphicsSimpleTextItem::keyReleaseEvent ( event ); QGraphicsSimpleTextItem::keyReleaseEvent ( event );
} }
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsSimpleTextItem::Init()
{
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
this->setAcceptHoverEvents(true);
QFont font = this->font();
font.setPointSize(font.pointSize()+20);
m_fontSize = font.pointSize();
this->setFont(font);
m_oldScale = minVisibleFontSize / m_fontSize;
setScale(m_oldScale);
}

View File

@ -88,6 +88,8 @@ private:
qint32 m_fontSize; qint32 m_fontSize;
SelectionType selectionType; SelectionType selectionType;
qreal m_oldScale; qreal m_oldScale;
void Init();
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -63,7 +63,7 @@ void VScenePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
{ {
const qreal scale = SceneScale(scene()); const qreal scale = SceneScale(scene());
if (m_namePoint->BaseFontSize()*scale < 5) if (m_namePoint->BaseFontSize()*scale < minVisibleFontSize)
{ {
m_namePoint->setVisible(false); m_namePoint->setVisible(false);
m_lineName->setVisible(false); m_lineName->setVisible(false);