Browse files

Fixed - tried to follow http://labs.qt.nokia.com/2010/06/17/youre-doi…

…ng-it-wrong/ when using threads
  • Loading branch information...
1 parent 96115fe commit 99c2b895cf64e82afc78aa1ff594f9fe1b9a006b Pierre Marchand committed Sep 20, 2010
View
2 src/CMakeLists.txt
@@ -205,7 +205,7 @@ shortcuts.h
systray.h
# tagseteditor.h
tagswidget.h
-textprogression.h
+#textprogression.h
tttableview.h
typotek.h
)
View
23 src/fmlayout.cpp
@@ -335,9 +335,9 @@ FMLayout::FMLayout ( QGraphicsScene * scene, FontItem * font , QRectF rect )
// onSceneProgressBar->setWidget ( progressBar );
// onSceneProgressBar->setZValue ( 1000 );
- connect ( this, SIGNAL ( paragraphFinished() ), this, SLOT( endOfParagraph() ) );
- connect ( this, SIGNAL ( layoutFinished() ), this, SLOT ( doDraw() ) );
- connect ( this, SIGNAL ( paintFinished() ), this, SLOT ( endOfRun() ) );
+// connect ( this, SIGNAL ( paragraphFinished() ), this, SLOT( endOfParagraph() ) );
+// connect ( this, SIGNAL ( layoutFinished() ), this, SLOT ( doDraw() ) );
+// connect ( this, SIGNAL ( paintFinished() ), this, SLOT ( endOfRun() ) );
FM_LAYOUT_NODE_SOON_F= 1200.0;
FM_LAYOUT_NODE_FIT_F= 1000.0;
@@ -390,7 +390,7 @@ FMLayout::~ FMLayout()
void FMLayout::run()
{
if(justRedraw)
- emit layoutFinished();
+ doDraw();
else
{
for ( int i ( 0 ); i < paragraphs.count() ; ++ i )
@@ -426,13 +426,15 @@ void FMLayout::run()
emit paragraphFinished();
}
- emit layoutFinished();
+ doDraw();
}
+ qDebug()<<"\tLayout Finished";
}
void FMLayout::doLayout ( const QList<GlyphList> & spec , double fs )
{
stopIt = false;
+ layoutIsFinished = false;
TextProgression *tp = TextProgression::getInstance();
@@ -471,11 +473,9 @@ void FMLayout::doLayout ( const QList<GlyphList> & spec , double fs )
paragraphs = spec;
optionHasChanged = false;
- // if ( node )
- // {
- // delete node;
- // node = 0;
- // }
+ run();
+ layoutIsFinished = true;
+ qDebug()<< "FMLayout::doLayout return";
}
void FMLayout::endOfRun()
@@ -505,6 +505,7 @@ void FMLayout::endOfRun()
void FMLayout::stopLayout()
{
stopIt = true;
+ layoutIsFinished = true;
}
void FMLayout::doGraph() // Has became doBreaks
@@ -570,7 +571,7 @@ void FMLayout::doLines()
for ( int lIdx ( 0 ); lIdx < maxIndex ; ++lIdx )
{
- if ( stopIt )
+ if ( stopIt || ((adjustedSampleInter * (lines.count() + 1)) > theRect.height()))
break;
int start1 ( /*!lIdx ?*/ indices[lIdx] /*: indices[lIdx] + 1*/ );
int end1 ( indices[ lIdx + 1 ] );
View
9 src/fmlayout.h
@@ -84,7 +84,7 @@ struct Node
-class FMLayout : public QThread
+class FMLayout : public QObject
{
Q_OBJECT
@@ -93,7 +93,6 @@ class FMLayout : public QThread
~FMLayout();
void doLayout(const QList<GlyphList>& spec , double fs);
// static FMLayout *getLayout();
- void run();
private://methods
/// Build a graph on node
@@ -103,11 +102,15 @@ class FMLayout : public QThread
void clearCaches();
+ void run();
+
public:// utils
double distance ( int start, int end, const GlyphList& gl , bool strip = false );
int sepCount( int start, int end, const GlyphList& gl);
void resetScene();
+ bool isLayoutFinished() {return layoutIsFinished;}
+
QList<int> breakList;
QList<int> hyphenList;
GlyphList theString;
@@ -155,6 +158,8 @@ class FMLayout : public QThread
bool deviceIndy;
QPointF origine;
+ bool layoutIsFinished;
+
public: //accessors
QRectF getRect()const{return theRect;}
void setRect(const QRectF& r){theRect = r;}
View
4 src/fontbook.cpp
@@ -444,7 +444,7 @@ void FontBook::doBookFromTemplate ( const QDomDocument &aTemplate )
tlay->setDeviceIndy ( true );
tlay->doLayout ( gl , conSubfamily[elemIndex].textStyle.fontsize );
- tlay->run();
+// tlay->run();
needed = tlay->drawnLines * conSubfamily[elemIndex].textStyle.lineheight;
@@ -564,7 +564,7 @@ void FontBook::doBookFromTemplate ( const QDomDocument &aTemplate )
alay->setDeviceIndy ( true );
alay->doLayout ( gl , conSubfamily[elemIndex].textStyle.fontsize );
- alay->run();
+// alay->run();
thePos.ry() += alay->drawnLines * conSubfamily[elemIndex].textStyle.lineheight;
renderedFont.append ( theFont );
View
2 src/mainviewwidget.cpp
@@ -1234,7 +1234,7 @@ void MainViewWidget::slotQuickSearch(const QString& text)
quickSearchTime.start();
hasText = listView->moveTo(quickSearchString);
}
- else if(t < quickSearchWait)
+ else if(t <= quickSearchWait)
{
if(sender() != quickSearch)
{
View
10 src/sampletoolbar.cpp
@@ -27,7 +27,7 @@ SampleToolBar::SampleToolBar(QWidget *parent) :
ui(new Ui::SampleToolBar)
{
ui->setupUi(this);
- setAutoFillBackground(true);
+// setAutoFillBackground(true);
connect(ui->liveSize, SIGNAL(valueChanged(double)), this, SIGNAL(SizeChanged(double)));
connect(ui->sampleButton, SIGNAL(toggled(bool)), this, SIGNAL(SampleToggled(bool)));
@@ -79,6 +79,14 @@ void SampleToolBar::toggle(Button b, bool c)
ui->opentypeButton->setChecked(c);
}
+void SampleToolBar::enableButton(Button b, bool c)
+{
+ if(b == SampleButton)
+ ui->sampleButton->setEnabled(c);
+ else if(b == OpenTypeButton)
+ ui->opentypeButton->setEnabled(c);
+}
+
void SampleToolBar::setScripts(const QStringList &ll)
{
ui->languageCombo->addItem(tr("Select language"), QString("NOSHAPER"));
View
2 src/sampletoolbar.h
@@ -47,6 +47,8 @@ class SampleToolBar : public QWidget
bool isChecked(Button b);
void toggle(Button b, bool c);
+ void enableButton(Button b, bool c);
+
void setScripts(const QStringList& ll);
QString getScript();
View
127 src/samplewidget.cpp
@@ -41,6 +41,7 @@
#include <QSettings>
#include <QStyledItemDelegate>
#include <QKeyEvent>
+#include <QThread>
QByteArray SampleWidget::State::toByteArray() const
@@ -86,9 +87,11 @@ SampleWidget::SampleWidget(const QString& fid, QWidget *parent) :
ui(new Ui::SampleWidget),
fontIdentifier(fid)
{
+ layoutTimer = new QTimer(this);
+ layoutWait = 1000;
layoutForPrint = false;
ui->setupUi(this);
- ui->textProgression->setVisible(false);
+// ui->textProgression->setVisible(false);
sampleToolBar = new SampleToolBar(this);
ui->sampleGridLayout->addWidget(sampleToolBar, 1,0, Qt::AlignRight | Qt::AlignBottom);
@@ -122,11 +125,12 @@ SampleWidget::SampleWidget(const QString& fid, QWidget *parent) :
ui->loremView_FT->locker = false;
ui->loremView_FT->fakePage();
-// QMap<QString, int> sTypes(FMShaperFactory::types());
-// for(QMap<QString, int>::iterator sIt = sTypes.begin(); sIt != sTypes.end() ; ++sIt)
-// {
-// ui->shaperTypeCombo->addItem(sIt.key(), sIt.value());
-// }
+ FontItem * cf(FMFontDb::DB()->Font(fid));
+ textLayoutVect = new FMLayout(loremScene, cf);
+ textLayoutFT = new FMLayout(ftScene, cf);
+
+ layoutThread = new QThread(this);
+ textLayoutFT->moveToThread(layoutThread);
QSettings settings;
State s;
@@ -136,12 +140,6 @@ SampleWidget::SampleWidget(const QString& fid, QWidget *parent) :
sampleRatio = 1.2;
sampleInterSize = sampleFontSize * sampleRatio;
- FontItem * cf(FMFontDb::DB()->Font(fid));
- textLayoutVect = new FMLayout(loremScene, cf);
- textLayoutFT = new FMLayout(ftScene, cf);
-
-
-
createConnections();
slotView(true);
}
@@ -179,7 +177,7 @@ void SampleWidget::createConnections()
connect ( ui->saveDefOTFBut, SIGNAL(released()),this,SLOT(slotDefaultOTF()));
connect ( ui->resetDefOTFBut, SIGNAL(released()),this,SLOT(slotResetOTF()));
- connect ( ui->textProgression, SIGNAL ( stateChanged ( ) ),this ,SLOT(slotProgressionChanged()));
+// connect ( ui->textProgression, SIGNAL ( stateChanged ( ) ),this ,SLOT(slotProgressionChanged()));
connect(ui->toolbar, SIGNAL(Print()), this, SLOT(slotPrint()));
connect(ui->toolbar, SIGNAL(Close()), this, SLOT(close()));
@@ -199,6 +197,8 @@ void SampleWidget::createConnections()
connect(ui->removeSampleButton, SIGNAL(clicked()), this, SLOT(slotRemoveSample()));
connect(sampleNameEditor, SIGNAL(closeEditor(QWidget*)), this, SLOT(slotSampleNameEdited(QWidget*)));
connect(ui->sampleEdit, SIGNAL(textChanged()), this, SLOT(slotUpdateSample()));
+
+ connect(layoutTimer, SIGNAL(timeout()), this, SLOT(slotUpdateSample()));
}
@@ -223,7 +223,7 @@ void SampleWidget::removeConnections()
disconnect ( ui->saveDefOTFBut, SIGNAL(released()),this,SLOT(slotDefaultOTF()));
disconnect ( ui->resetDefOTFBut, SIGNAL(released()),this,SLOT(slotResetOTF()));
- disconnect ( ui->textProgression, SIGNAL ( stateChanged ( ) ),this ,SLOT(slotProgressionChanged()));
+// disconnect ( ui->textProgression, SIGNAL ( stateChanged ( ) ),this ,SLOT(slotProgressionChanged()));
disconnect(ui->toolbar, SIGNAL(Print()), this, SLOT(slotPrint()));
disconnect(ui->toolbar, SIGNAL(Close()), this, SLOT(close()));
@@ -327,6 +327,7 @@ void SampleWidget::setState(const SampleWidget::State &s)
void SampleWidget::slotView ( bool needDeRendering )
{
+ qDebug()<<"SampleWidget::slotView ";
QTime t;
t.start();
FontItem *f(FMFontDb::DB()->Font( fontIdentifier ));
@@ -337,51 +338,44 @@ void SampleWidget::slotView ( bool needDeRendering )
// f->deRenderAll();
}
-// bool wantDeviceDependant = (!layoutForPrint) ? ui->freetypeRadio->isChecked() : false;
bool wantDeviceDependant = !layoutForPrint;
- // unsigned int storedHinting(f->getFTHintMode());
if(wantDeviceDependant)
{
f->setFTHintMode(hinting());
}
- if(ui->textProgression->inLine() == TextProgression::INLINE_LTR )
+// if(ui->textProgression->inLine() == TextProgression::INLINE_LTR )
f->setProgression(PROGRESSION_LTR );
- else if(ui->textProgression->inLine() == TextProgression::INLINE_RTL )
- f->setProgression(PROGRESSION_RTL);
- else if(ui->textProgression->inLine() == TextProgression::INLINE_TTB )
- f->setProgression(PROGRESSION_TTB );
- else if(ui->textProgression->inLine() == TextProgression::INLINE_BTT )
- f->setProgression(PROGRESSION_BTT);
+// else if(ui->textProgression->inLine() == TextProgression::INLINE_RTL )
+// f->setProgression(PROGRESSION_RTL);
+// else if(ui->textProgression->inLine() == TextProgression::INLINE_TTB )
+// f->setProgression(PROGRESSION_TTB );
+// else if(ui->textProgression->inLine() == TextProgression::INLINE_BTT )
+// f->setProgression(PROGRESSION_BTT);
f->setFTRaster ( wantDeviceDependant );
- f->setShaperType(ui->shaperTypeCombo->itemData( ui->shaperTypeCombo->currentIndex() ).toInt() );
- if ( ui->loremView->isVisible() || ui->loremView_FT->isVisible() || layoutForPrint)
+// if ( ui->loremView->isVisible() || ui->loremView_FT->isVisible() || layoutForPrint)
{
- // qDebug()<<"lv(ft) is visible";
- if(textLayoutFT->isRunning())
+ if(!textLayoutFT->isLayoutFinished())
+ {
textLayoutFT->stopLayout();
- else if(textLayoutVect->isRunning())
- textLayoutVect->stopLayout();
- else
+ qDebug()<<"\tLayout stopped";
+ }
+// else if(textLayoutVect->isRunning())
+// textLayoutVect->stopLayout();
+// else
{
- // qDebug()<<"tl is NOT running";
- QGraphicsScene *targetScene;
+ qDebug()<<"\tStart layout";
ui->loremView_FT->unSheduleUpdate();
ui->loremView->unSheduleUpdate();
FMLayout * textLayout;
- if(ui->loremView->isVisible() || layoutForPrint)
- {
+ if(layoutForPrint)
textLayout = textLayoutVect;
- }
- else if(ui->loremView_FT->isVisible())
- {
+ else
textLayout = textLayoutFT;
- }
bool processFeatures = f->isOpenType() && !deFillOTTree().isEmpty();
-// QString script = ui->langCombo->currentText();
QString script(sampleToolBar->getScript());
bool processScript( !script.isEmpty() );
textLayout->setDeviceIndy(!wantDeviceDependant);
@@ -400,55 +394,24 @@ void SampleWidget::slotView ( bool needDeRendering )
}
else if(processFeatures)
{
- // Experimental code to handle alternate is commented out
- // Do not uncomment
- // FMAltContext * actx ( FMAltContextLib::SetCurrentContext(sampleTextTree->currentText(), f->path()));
- // int rs(0);
- // actx->setPar(rs);
for(int p(0);p<stl.count();++p)
{
list << f->glyphs( stl[p] , fSize, deFillOTTree());
- // actx->setPar(++rs);
}
- // actx->cleanup();
- // FMAltContextLib::SetCurrentContext(sampleTextTree->currentText(), f->path());
}
else
{
for(int p(0);p<stl.count();++p)
list << f->glyphs( stl[p] , fSize );
}
textLayout->doLayout(list, fSize);
- // if (loremView->isVisible() /*&& fitViewCheck->isChecked()*/ )
- // {
- // loremView->fitInView ( textLayout->getRect(), Qt::KeepAspectRatio );
- // }
- if(!layoutForPrint)
- textLayout->start(QThread::LowestPriority);
- else
- textLayout->run();
- if(ui->loremView->isVisible())
- {
- QPointF texttopLeft(ui->loremView->mapFromScene(textLayout->getRect().topLeft()));
- ui->loremView->translate((10 + fSize) - texttopLeft.x() , (10 + fSize) - texttopLeft.y());
- }
- else if(ui->loremView_FT->isVisible())
{
QPointF texttopLeft(ui->loremView_FT->mapFromScene(textLayout->getRect().topLeft()));
ui->loremView_FT->translate( 10 -texttopLeft.x(), 10 -texttopLeft.y());
}
}
}
- else if(!ui->loremView->isVisible() && !ui->loremView_FT->isVisible())
- {
- ui->loremView->sheduleUpdate();
- ui->loremView_FT->sheduleUpdate();
- }
-
-
- // slotUpdateGView();
- // slotInfoFont();
}
@@ -944,6 +907,28 @@ void SampleWidget::slotEditSample()
void SampleWidget::slotUpdateSample()
{
typotek::getInstance()->changeSample(ui->sampleTextTree->currentItem()->text(0), ui->sampleEdit->toPlainText());
- slotUpdateRView();
+ slotView(true);
+// if(firstUpdateRequest)
+// {
+// typotek::getInstance()->changeSample(ui->sampleTextTree->currentItem()->text(0), ui->sampleEdit->toPlainText());
+// slotView(true);
+// firstUpdateRequest = false;
+// firstUpdateRequestTimeStamp = layoutTime.elapsed();
+// }
+// else
+// {
+// if((layoutTime.elapsed() - firstUpdateRequestTimeStamp) < layoutWait)
+// {
+// firstUpdateRequestTimeStamp = layoutTime.elapsed();
+// layoutTimer->start(layoutWait);
+// }
+// else
+// {
+// layoutTimer->stop();
+// firstUpdateRequest = true;
+// typotek::getInstance()->changeSample(ui->sampleTextTree->currentItem()->text(0), ui->sampleEdit->toPlainText());
+// slotView(true);
+// }
+// }
}
View
11 src/samplewidget.h
@@ -22,9 +22,11 @@
#define SAMPLEWIDGET_H
#include "floatingwidget.h"
+#include "fmotf.h"
+
#include <QString>
#include <QByteArray>
-#include "fmotf.h"
+#include <QTime>
class QGraphicsScene;
class FMLayout;
@@ -35,6 +37,7 @@ class QTimer;
class SampleToolBar;
class QTreeWidgetItem;
class QStyledItemDelegate;
+class QThread;
namespace Ui {
class SampleWidget;
@@ -125,6 +128,12 @@ class SampleWidget : public FloatingWidget
OTFSet deFillOTTree();
bool layoutForPrint;
+ bool firstUpdateRequest;
+ int firstUpdateRequestTimeStamp;
+ QTime layoutTime;
+ QTimer *layoutTimer;
+ int layoutWait;
+ QThread * layoutThread;
void reSize(double fSize, double lSize){sampleFontSize = fSize; sampleInterSize = lSize;}
View
17 src/samplewidget.ui
@@ -86,7 +86,7 @@
<property name="margin">
<number>3</number>
</property>
- <item row="3" column="1">
+ <item row="2" column="1">
<widget class="QComboBox" name="langCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -96,7 +96,7 @@
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="1" column="1">
<widget class="QComboBox" name="shaperTypeCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -106,7 +106,7 @@
</property>
</widget>
</item>
- <item row="3" column="0">
+ <item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@@ -122,7 +122,7 @@
</property>
</widget>
</item>
- <item row="2" column="0">
+ <item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@@ -139,9 +139,6 @@
</widget>
</item>
<item row="0" column="0" colspan="2">
- <widget class="TextProgression" name="textProgression" native="true"/>
- </item>
- <item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="useShaperCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -318,12 +315,6 @@
<header>fmsampletextview.h</header>
</customwidget>
<customwidget>
- <class>TextProgression</class>
- <extends>QWidget</extends>
- <header>textprogression.h</header>
- <container>1</container>
- </customwidget>
- <customwidget>
<class>FloatingWidgetToolBar</class>
<extends>QWidget</extends>
<header>floatingwidgettoolbar.h</header>
View
59 src/textprogression.cpp
@@ -12,48 +12,47 @@
#include "textprogression.h"
TextProgression *TextProgression::instance = 0;
-TextProgression::TextProgression(QWidget * parent)
- :QWidget(parent)
+TextProgression::TextProgression()
{
instance = this;
- setupUi(this);
+// setupUi(this);
- connect(inlineBTT,SIGNAL(released()),this,SLOT(forwardStateChanged()));
- connect(inlineRTL,SIGNAL(released()),this,SLOT(forwardStateChanged()));
- connect(inlineLTR,SIGNAL(released()),this,SLOT(forwardStateChanged()));
- connect(inlineTTB,SIGNAL(released()),this,SLOT(forwardStateChanged()));
- connect(blockTTB,SIGNAL(released()),this,SLOT(forwardStateChanged()));
- connect(blockRTL,SIGNAL(released()),this,SLOT(forwardStateChanged()));
- connect(blockLTR,SIGNAL(released()),this,SLOT(forwardStateChanged()));
+// connect(inlineBTT,SIGNAL(released()),this,SLOT(forwardStateChanged()));
+// connect(inlineRTL,SIGNAL(released()),this,SLOT(forwardStateChanged()));
+// connect(inlineLTR,SIGNAL(released()),this,SLOT(forwardStateChanged()));
+// connect(inlineTTB,SIGNAL(released()),this,SLOT(forwardStateChanged()));
+// connect(blockTTB,SIGNAL(released()),this,SLOT(forwardStateChanged()));
+// connect(blockRTL,SIGNAL(released()),this,SLOT(forwardStateChanged()));
+// connect(blockLTR,SIGNAL(released()),this,SLOT(forwardStateChanged()));
}
TextProgression::Progression TextProgression::inBlock()
{
- if(blockTTB->isChecked())
- return BLOCK_TTB;
- else if(blockRTL->isChecked())
- return BLOCK_RTL;
- else if(blockLTR->isChecked())
- return BLOCK_LTR;
+// if(blockTTB->isChecked())
+// return BLOCK_TTB;
+// else if(blockRTL->isChecked())
+// return BLOCK_RTL;
+// else if(blockLTR->isChecked())
+// return BLOCK_LTR;
- return UNDEFINED;
+ return BLOCK_TTB;
}
TextProgression::Progression TextProgression::inLine()
{
- if(inlineLTR->isChecked())
- return INLINE_LTR;
- else if(inlineRTL->isChecked())
- return INLINE_RTL;
- else if(inlineTTB->isChecked())
- return INLINE_TTB;
- else if(inlineBTT->isChecked())
- return INLINE_BTT;
+// if(inlineLTR->isChecked())
+// return INLINE_LTR;
+// else if(inlineRTL->isChecked())
+// return INLINE_RTL;
+// else if(inlineTTB->isChecked())
+// return INLINE_TTB;
+// else if(inlineBTT->isChecked())
+// return INLINE_BTT;
- return UNDEFINED;
+ return INLINE_LTR;
}
-void TextProgression::forwardStateChanged( )
-{
- emit stateChanged();
-}
+//void TextProgression::forwardStateChanged( )
+//{
+// emit stateChanged();
+//}
View
16 src/textprogression.h
@@ -12,26 +12,26 @@
#ifndef TEXTPROGRESSION_H
#define TEXTPROGRESSION_H
-#include "ui_textprogression.h"
+//#include "ui_textprogression.h"
-class TextProgression : public QWidget, private Ui::TextProgressionWidget
+class TextProgression
{
- Q_OBJECT
+
public:
enum Progression {INLINE_LTR, INLINE_RTL, INLINE_TTB, INLINE_BTT, BLOCK_TTB, BLOCK_LTR, BLOCK_RTL, UNDEFINED};
- TextProgression(QWidget *parent);
+ TextProgression();
Progression inBlock();
Progression inLine();
static TextProgression* getInstance(){return instance;}
private:
static TextProgression *instance;
- signals:
- void stateChanged();
- private slots:
- void forwardStateChanged();
+// signals:
+// void stateChanged();
+// private slots:
+// void forwardStateChanged();
};
#endif

0 comments on commit 99c2b89

Please sign in to comment.