Commit c68919e1 authored by Martin Küttler's avatar Martin Küttler
Browse files

Some cleaning up

 - Changed tabs to spaces (that's why so many files changed)
 - Removed an unnecessary cast in worksheetview.cpp
parent 2cb68db7
......@@ -38,14 +38,14 @@ ActionBar::~ActionBar()
}
WorksheetToolButton* ActionBar::addButton(const KIcon& icon, QString toolTip,
QObject* receiver, const char* method )
QObject* receiver, const char* method )
{
WorksheetToolButton* button = new WorksheetToolButton(this);
button->setIcon(icon);
button->setIconScale(worksheet()->epsRenderer()->scale());
button->setToolTip(toolTip);
if (receiver && method)
connect(button, SIGNAL(clicked()), receiver, method);
connect(button, SIGNAL(clicked()), receiver, method);
m_pos -= button->width() + 2;
m_height = (m_height > button->height()) ? m_height : button->height();
button->setPos(m_pos, 4);
......@@ -63,7 +63,7 @@ void ActionBar::updatePosition(const QSizeF& parentSize)
setPos(parentSize.width(), 0);
const qreal scale = worksheet()->epsRenderer()->scale();
foreach(WorksheetToolButton* button, m_buttons) {
button->setIconScale(scale);
button->setIconScale(scale);
}
}
......
......@@ -37,8 +37,8 @@ class ActionBar : public QGraphicsObject
~ActionBar();
WorksheetToolButton* addButton(const KIcon& icon, QString toolTip,
QObject* receiver = 0,
const char* method = 0);
QObject* receiver = 0,
const char* method = 0);
void addSpace();
void updatePosition(const QSizeF& parentSize);
......
......@@ -31,7 +31,7 @@ AnimationResultItem::AnimationResultItem(QGraphicsObject* parent)
: WorksheetImageItem(parent), ResultItem(), m_height(0), m_movie(0)
{
connect(this, SIGNAL(removeResult()), parentEntry(),
SLOT(removeResult()));
SLOT(removeResult()));
}
AnimationResultItem::~AnimationResultItem()
......@@ -52,16 +52,16 @@ void AnimationResultItem::populateMenu(KMenu* menu, const QPointF& pos)
menu->addSeparator();
if (m_movie) {
if (m_movie->state() == QMovie::Running)
menu->addAction(KIcon("media-playback-pause"), i18n("Pause"),
this, SLOT(pauseMovie()));
else
menu->addAction(KIcon("media-playback-start"), i18n("Start"),
m_movie, SLOT(start()));
if (m_movie->state() == QMovie::Running ||
m_movie->state() == QMovie::Paused)
menu->addAction(KIcon("media-playback-stop"), i18n("Stop"),
this, SLOT(stopMovie()));
if (m_movie->state() == QMovie::Running)
menu->addAction(KIcon("media-playback-pause"), i18n("Pause"),
this, SLOT(pauseMovie()));
else
menu->addAction(KIcon("media-playback-start"), i18n("Start"),
m_movie, SLOT(start()));
if (m_movie->state() == QMovie::Running ||
m_movie->state() == QMovie::Paused)
menu->addAction(KIcon("media-playback-stop"), i18n("Stop"),
this, SLOT(stopMovie()));
}
kDebug() << "populate Menu";
emit menuCreated(menu, mapToParent(pos));
......@@ -72,12 +72,12 @@ ResultItem* AnimationResultItem::updateFromResult(Cantor::Result* result)
QMovie* mov;
switch(result->type()) {
case Cantor::AnimationResult::Type:
mov = static_cast<QMovie*>(result->data().value<QObject*>());
setMovie(mov);
return this;
mov = static_cast<QMovie*>(result->data().value<QObject*>());
setMovie(mov);
return this;
default:
deleteLater();
return create(parentEntry(), result);
deleteLater();
return create(parentEntry(), result);
}
}
......@@ -89,17 +89,17 @@ QRectF AnimationResultItem::boundingRect() const
void AnimationResultItem::setMovie(QMovie* movie)
{
if (m_movie) {
m_movie->disconnect(this, SLOT(updateFrame()));
m_movie->disconnect(this, SLOT(updateSize()));
m_movie->disconnect(this, SLOT(updateFrame()));
m_movie->disconnect(this, SLOT(updateSize()));
}
m_movie = movie;
m_height = 0;
if (m_movie) {
connect(m_movie, SIGNAL(frameChanged(int)), this,
SLOT(updateFrame()));
connect(m_movie, SIGNAL(resized(const QSize&)),
this, SLOT(updateSize(const QSize&)));
m_movie->start();
connect(m_movie, SIGNAL(frameChanged(int)), this,
SLOT(updateFrame()));
connect(m_movie, SIGNAL(resized(const QSize&)),
this, SLOT(updateSize(const QSize&)));
m_movie->start();
}
}
......@@ -112,8 +112,8 @@ void AnimationResultItem::updateFrame()
void AnimationResultItem::updateSize(const QSize& size)
{
if (m_height != size.height()) {
m_height = size.height();
emit sizeChanged();
m_height = size.height();
emit sizeChanged();
}
}
......@@ -128,16 +128,16 @@ void AnimationResultItem::saveResult()
void AnimationResultItem::stopMovie()
{
if (m_movie) {
m_movie->stop();
m_movie->jumpToFrame(0);
worksheet()->update(mapRectToScene(boundingRect()));
m_movie->stop();
m_movie->jumpToFrame(0);
worksheet()->update(mapRectToScene(boundingRect()));
}
}
void AnimationResultItem::pauseMovie()
{
if (m_movie)
m_movie->setPaused(true);
m_movie->setPaused(true);
}
void AnimationResultItem::deleteLater()
......
......@@ -120,18 +120,18 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
connect(savePlain, SIGNAL(triggered()), this, SLOT(fileSavePlain()));
KAction* find=KStandardAction::find(this, SLOT(showSearchBar()),
actionCollection());
actionCollection());
find->setPriority(QAction::LowPriority);
KAction* replace=KStandardAction::replace(this, SLOT(showExtendedSearchBar()),
actionCollection());
actionCollection());
replace->setPriority(QAction::LowPriority);
m_findNext = KStandardAction::findNext(this, SLOT(findNext()),
actionCollection());
actionCollection());
m_findNext->setEnabled(false);
m_findPrev = KStandardAction::findPrev(this, SLOT(findPrev()),
actionCollection());
actionCollection());
m_findPrev->setEnabled(false);
KAction* latexExport=new KAction(i18n("Export to LaTeX"), actionCollection());
......@@ -276,7 +276,7 @@ CantorPart::~CantorPart()
delete m_scriptEditor;
}
if (m_searchBar)
delete m_searchBar;
delete m_searchBar;
}
void CantorPart::setReadWrite(bool rw)
......@@ -343,7 +343,7 @@ bool CantorPart::saveFile()
if (url().isEmpty())
fileSaveAs();
else
m_worksheet->save( localFilePath() );
m_worksheet->save( localFilePath() );
setModified(false);
return true;
......@@ -364,9 +364,9 @@ void CantorPart::fileSaveAs()
QString file_name = KFileDialog::getSaveFileName(KUrl(), filter, widget());
if (!file_name.isEmpty()) {
if (!file_name.endsWith(QLatin1String(".cws")) &&
!file_name.endsWith(QLatin1String(".mws")))
file_name += ".cws";
if (!file_name.endsWith(QLatin1String(".cws")) &&
!file_name.endsWith(QLatin1String(".mws")))
file_name += ".cws";
saveAs(file_name);
}
......@@ -468,7 +468,7 @@ void CantorPart::worksheetSessionChanged()
void CantorPart::initialized()
{
if (m_worksheet->isEmpty())
m_worksheet->appendCommandEntry();
m_worksheet->appendCommandEntry();
m_worksheetview->setEnabled(true);
m_worksheetview->setFocus();
setStatusMessage(i18n("Initialization complete"));
......@@ -585,10 +585,10 @@ void CantorPart::runCommand(const QString& cmd)
void CantorPart::showSearchBar()
{
if (!m_searchBar) {
m_searchBar = new SearchBar(widget(), m_worksheet);
widget()->layout()->addWidget(m_searchBar);
connect(m_searchBar, SIGNAL(destroyed(QObject*)),
this, SLOT(searchBarDeleted()));
m_searchBar = new SearchBar(widget(), m_worksheet);
widget()->layout()->addWidget(m_searchBar);
connect(m_searchBar, SIGNAL(destroyed(QObject*)),
this, SLOT(searchBarDeleted()));
}
m_findNext->setEnabled(true);
......@@ -601,10 +601,10 @@ void CantorPart::showSearchBar()
void CantorPart::showExtendedSearchBar()
{
if (!m_searchBar) {
m_searchBar = new SearchBar(widget(), m_worksheet);
widget()->layout()->addWidget(m_searchBar);
connect(m_searchBar, SIGNAL(destroyed(QObject*)),
this, SLOT(searchBarDeleted()));
m_searchBar = new SearchBar(widget(), m_worksheet);
widget()->layout()->addWidget(m_searchBar);
connect(m_searchBar, SIGNAL(destroyed(QObject*)),
this, SLOT(searchBarDeleted()));
}
m_findNext->setEnabled(true);
......@@ -617,13 +617,13 @@ void CantorPart::showExtendedSearchBar()
void CantorPart::findNext()
{
if (m_searchBar)
m_searchBar->next();
m_searchBar->next();
}
void CantorPart::findPrev()
{
if (m_searchBar)
m_searchBar->prev();
m_searchBar->prev();
}
void CantorPart::searchBarDeleted()
......
......@@ -145,7 +145,7 @@ protected slots:
*/
void blockStatusBar();
/** Removes the block from the StatusBar, and shows the last one of the StatusMessages that
where set during the block
where set during the block
**/
void unblockStatusBar();
private:
......
This diff is collapsed.
......@@ -82,8 +82,8 @@ class CommandEntry : public WorksheetEntry
WorksheetTextItem* highlightItem();
WorksheetCursor search(QString pattern, unsigned flags,
QTextDocument::FindFlags qt_flags,
const WorksheetCursor& pos = WorksheetCursor());
QTextDocument::FindFlags qt_flags,
const WorksheetCursor& pos = WorksheetCursor());
public slots:
bool evaluateCurrentItem();
......@@ -122,8 +122,8 @@ class CommandEntry : public WorksheetEntry
private:
enum CompletionMode {
PreliminaryCompletion,
FinalCompletion
PreliminaryCompletion,
FinalCompletion
};
private slots:
void invalidate();
......
......@@ -61,22 +61,22 @@ QTextImageFormat EpsRenderer::render(QTextDocument *document, const KUrl& url)
if(s.isValid())
{
epsCharFormat.setName(internal.url());
epsCharFormat.setWidth(s.width());
epsCharFormat.setHeight(s.height());
epsCharFormat.setWidth(s.width());
epsCharFormat.setHeight(s.height());
}
return epsCharFormat;
}
QTextImageFormat EpsRenderer::render(QTextDocument *document,
const Cantor::LatexRenderer* latex)
const Cantor::LatexRenderer* latex)
{
QTextImageFormat format = render(document, latex->imagePath());
if (!format.name().isEmpty()) {
format.setProperty(CantorFormula, latex->method());
format.setProperty(ImagePath, latex->imagePath());
format.setProperty(Code, latex->latexCode());
format.setProperty(CantorFormula, latex->method());
format.setProperty(ImagePath, latex->imagePath());
format.setProperty(Code, latex->latexCode());
}
return format;
......@@ -110,12 +110,12 @@ QImage EpsRenderer::renderToImage(const KUrl& url, QSizeF* size)
spectre_document_get_page_size(doc, &wdoc, &hdoc);
if(m_useHighRes) {
scale=1.2*4.0; //1.2 scaling factor, to make it look nice, 4x for high resolution
w = 1.2 * wdoc;
h = 1.2 * hdoc;
w = 1.2 * wdoc;
h = 1.2 * hdoc;
} else {
scale=1.8*m_scale;
w = 1.8 * wdoc;
h = 1.8 * hdoc;
w = 1.8 * wdoc;
h = 1.8 * hdoc;
}
kDebug()<<"scale: "<<scale;
......@@ -132,7 +132,7 @@ QImage EpsRenderer::renderToImage(const KUrl& url, QSizeF* size)
spectre_render_context_free(rc);
if (size)
*size = QSizeF(w,h);
*size = QSizeF(w,h);
return img;
#else
return QImage();
......
......@@ -37,13 +37,13 @@ class EpsRenderer
~EpsRenderer();
enum FormulaProperties {CantorFormula = 1, ImagePath = 2, Code = 3,
Delimiter = 4};
Delimiter = 4};
enum FormulaType {LatexFormula = Cantor::LatexRenderer::LatexMethod,
MmlFormula = Cantor::LatexRenderer::MmlMethod};
MmlFormula = Cantor::LatexRenderer::MmlMethod};
QTextImageFormat render(QTextDocument *document, const KUrl& url);
QTextImageFormat render(QTextDocument *document,
const Cantor::LatexRenderer* latex);
QTextImageFormat render(QTextDocument *document,
const Cantor::LatexRenderer* latex);
void setScale(qreal scale);
qreal scale();
......
......@@ -40,7 +40,7 @@ ImageEntry::ImageEntry(Worksheet* worksheet) : WorksheetEntry(worksheet)
m_printSize.heightUnit = ImageSize::Auto;
m_useDisplaySizeForPrinting = true;
connect(m_imageWatcher, SIGNAL(fileChanged(const QString&)),
this, SLOT(updateEntry()));
this, SLOT(updateEntry()));
setFlag(QGraphicsItem::ItemIsFocusable);
updateEntry();
......@@ -84,7 +84,7 @@ void ImageEntry::setContent(const QDomElement& content, const KZip& file)
Q_UNUSED(file);
static QStringList unitNames;
if (unitNames.isEmpty())
unitNames << "(auto)" << "px" << "%";
unitNames << "(auto)" << "px" << "%";
QDomElement pathElement = content.firstChildElement("Path");
QDomElement displayElement = content.firstChildElement("Display");
......@@ -108,7 +108,7 @@ QDomElement ImageEntry::toXml(QDomDocument& doc, KZip* archive)
static QStringList unitNames;
if (unitNames.isEmpty())
unitNames << "(auto)" << "px" << "%";
unitNames << "(auto)" << "px" << "%";
QDomElement image = doc.createElement("Image");
QDomElement path = doc.createElement("Path");
......@@ -156,17 +156,17 @@ QString ImageEntry::latexSizeString(const ImageSize& imgSize)
QString sizeString="";
if (imgSize.widthUnit == ImageSize::Auto &&
imgSize.heightUnit == ImageSize::Auto)
imgSize.heightUnit == ImageSize::Auto)
return QString("");
if (imgSize.widthUnit == ImageSize::Percent) {
if (imgSize.heightUnit == ImageSize::Auto ||
(imgSize.heightUnit == ImageSize::Percent &&
imgSize.width == imgSize.height))
return "[scale=" + QString::number(imgSize.width / 100) + "]";
// else? We could set the size based on the actual image size
if (imgSize.heightUnit == ImageSize::Auto ||
(imgSize.heightUnit == ImageSize::Percent &&
imgSize.width == imgSize.height))
return "[scale=" + QString::number(imgSize.width / 100) + "]";
// else? We could set the size based on the actual image size
} else if (imgSize.widthUnit == ImageSize::Auto &&
imgSize.heightUnit == ImageSize::Percent) {
imgSize.heightUnit == ImageSize::Percent) {
return "[scale=" + QString::number(imgSize.height / 100) + "]";
}
......@@ -193,56 +193,56 @@ bool ImageEntry::evaluate(EvaluationOption evalOp)
qreal ImageEntry::height()
{
if (m_imageItem && m_imageItem->isVisible())
return m_imageItem->height();
return m_imageItem->height();
else
return m_textItem->height();
return m_textItem->height();
}
void ImageEntry::updateEntry()
{
qreal oldHeight = height();
if (m_imagePath.isEmpty()) {
m_textItem->setPlainText(i18n("Right click here to insert image"));
m_textItem->setVisible(true);
if (m_imageItem)
m_imageItem->setVisible(false);
m_textItem->setPlainText(i18n("Right click here to insert image"));
m_textItem->setVisible(true);
if (m_imageItem)
m_imageItem->setVisible(false);
}
else {
if (!m_imageItem)
m_imageItem = new WorksheetImageItem(this);
if (m_imagePath.toLower().endsWith(".eps")) {
m_imageItem->setEps(m_imagePath);
} else {
QImage img(m_imagePath);
m_imageItem->setImage(img);
}
if (!m_imageItem->imageIsValid()) {
const QString msg = i18n("Cannot load image %1").arg(m_imagePath);
m_textItem->setPlainText(msg);
m_textItem->setVisible(true);
m_imageItem->setVisible(false);
} else {
QSizeF size;
if (worksheet()->isPrinting() && ! m_useDisplaySizeForPrinting)
size = imageSize(m_printSize);
else
size = imageSize(m_displaySize);
// Hack: Eps images need to be scaled
if (m_imagePath.toLower().endsWith(".eps"))
size /= worksheet()->epsRenderer()->scale();
m_imageItem->setSize(size);
kDebug() << size;
m_textItem->setVisible(false);
m_imageItem->setVisible(true);
}
if (!m_imageItem)
m_imageItem = new WorksheetImageItem(this);
if (m_imagePath.toLower().endsWith(".eps")) {
m_imageItem->setEps(m_imagePath);
} else {
QImage img(m_imagePath);
m_imageItem->setImage(img);
}
if (!m_imageItem->imageIsValid()) {
const QString msg = i18n("Cannot load image %1").arg(m_imagePath);
m_textItem->setPlainText(msg);
m_textItem->setVisible(true);
m_imageItem->setVisible(false);
} else {
QSizeF size;
if (worksheet()->isPrinting() && ! m_useDisplaySizeForPrinting)
size = imageSize(m_printSize);
else
size = imageSize(m_displaySize);
// Hack: Eps images need to be scaled
if (m_imagePath.toLower().endsWith(".eps"))
size /= worksheet()->epsRenderer()->scale();
m_imageItem->setSize(size);
kDebug() << size;
m_textItem->setVisible(false);
m_imageItem->setVisible(true);
}
}
kDebug() << oldHeight << height();
if (oldHeight != height())
recalculateSize();
recalculateSize();
}
QSizeF ImageEntry::imageSize(const ImageSize& imgSize)
......@@ -250,26 +250,26 @@ QSizeF ImageEntry::imageSize(const ImageSize& imgSize)
const QSize& srcSize = m_imageItem->imageSize();
qreal w, h;
if (imgSize.heightUnit == ImageSize::Percent)
h = srcSize.height() * imgSize.height / 100;
h = srcSize.height() * imgSize.height / 100;
else if (imgSize.heightUnit == ImageSize::Pixel)
h = imgSize.height;
h = imgSize.height;
if (imgSize.widthUnit == ImageSize::Percent)
w = srcSize.width() * imgSize.width / 100;
w = srcSize.width() * imgSize.width / 100;
else if (imgSize.widthUnit == ImageSize::Pixel)
w = imgSize.width;
w = imgSize.width;
if (imgSize.widthUnit == ImageSize::Auto) {
if (imgSize.heightUnit == ImageSize::Auto)
return QSizeF(srcSize.width(), srcSize.height());
else if (h == 0)
w = 0;
else
w = h / srcSize.height() * srcSize.width();
if (imgSize.heightUnit == ImageSize::Auto)
return QSizeF(srcSize.width(), srcSize.height());
else if (h == 0)
w = 0;
else
w = h / srcSize.height() * srcSize.width();
} else if (imgSize.heightUnit == ImageSize::Auto) {
if (w == 0)
h = 0;
else
h = w / srcSize.width() * srcSize.height();
if (w == 0)
h = 0;
else
h = w / srcSize.width() * srcSize.height();
}
return QSizeF(w,h);
......@@ -279,23 +279,23 @@ void ImageEntry::startConfigDialog()
{
ImageSettingsDialog* dialog = new ImageSettingsDialog(worksheet()->worksheetView());
dialog->setData(m_imagePath, m_displaySize, m_printSize,
m_useDisplaySizeForPrinting);
m_useDisplaySizeForPrinting);
connect(dialog, SIGNAL(dataChanged(const QString&, const ImageSize&,
const ImageSize&, bool)),
this, SLOT(setImageData(const QString&, const ImageSize&,
const ImageSize&, bool)));
const ImageSize&, bool)),
this, SLOT(setImageData(const QString&, const ImageSize&,
const ImageSize&, bool)));
dialog->show();
}
void ImageEntry::setImageData(const QString& path,
const ImageSize& displaySize,
const ImageSize& printSize,
bool useDisplaySizeForPrinting)
const ImageSize& displaySize,
const ImageSize& printSize,
bool useDisplaySizeForPrinting)
{
if (path != m_imagePath) {
m_imageWatcher->removePath(m_imagePath);
m_imageWatcher->addPath(path);
m_imagePath = path;
m_imageWatcher->removePath(m_imagePath);
m_imageWatcher->addPath(path);
m_imagePath = path;
}
m_displaySize = displaySize;
......@@ -308,19 +308,19 @@ void ImageEntry::setImageData(const QString& path,
void ImageEntry::addActionsToBar(ActionBar* actionBar)
{
actionBar->addButton(KIcon("configure"), i18n("Configure Image"),
this, SLOT(startConfigDialog()));
this, SLOT(startConfigDialog()));
}
void ImageEntry::layOutForWidth(double w, bool force)
{
if (size().width() == w && !force)
return;
return;
if (m_imageItem && m_imageItem->isVisible())
m_imageItem->setGeometry(0, 0, w, true);
m_imageItem->setGeometry(0, 0, w, true);
else
m_textItem->setGeometry(0, 0, w, true);
m_textItem->setGeometry(0, 0, w, true);
setSize(QSizeF(w, height() + VerticalMargin));
}
......
......@@ -62,7 +62,7 @@ class ImageEntry : public WorksheetEntry
void populateMenu(KMenu *menu, const QPointF& pos);
void startConfigDialog();
void setImageData(const QString& path, const ImageSize& displaySize,