diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e5d9105 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: Test + +on: + pull_request: {} + push: + branches: master + +jobs: + test: + strategy: + matrix: + python-version: ['3.12'] + os: [ubuntu-latest] + + name: Python ${{ matrix.os }} ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + sudo apt update + sudo apt install time -y + sudo apt install qtbase5-dev qt5-qmake libjpeg-dev libpng-dev libqt5svg5-dev libtiff-dev -y + + - name: Compile + run: ./build.py diff --git a/.gitignore b/.gitignore index 5ed9086..9d57f0c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,9 +25,5 @@ win32 *._* -chemvp0.2.tgz -TODO.txt - # compilation directory -objdir/ -obj/ +build/ diff --git a/README.rst b/README.rst index c3bf89e..b25633c 100644 --- a/README.rst +++ b/README.rst @@ -71,9 +71,7 @@ source is pretty simple. 1. Download and install Qt5 and necessary libraries - On Ubuntu,: `aptitude install qt5-default libjpeg-dev libpng-dev libqt5svg5-dev libtiff-dev` -2. Head into the compilation directory in the cheMVP source folder (e.g. `mkdir build; cd build`) -3. Type '../qmake_script' -4. Type 'make' +2. Type `./build.py` WARRANTY diff --git a/build.py b/build.py new file mode 100755 index 0000000..9c8f31e --- /dev/null +++ b/build.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +import os +import sys +from glob import glob +from subprocess import check_call + +filename = "cheMVP.pro" +N_PROCS = os.cpu_count() + +os.makedirs("build", exist_ok=True) +os.chdir("build") + +sections = { + "SOURCES": "cpp", + "HEADERS": "h", + "RESOURCES": "qrc", +} + +out = "\n".join( + f"{section} = " + " \\ \n".join(glob(f"../src/*.{ext}")) + for section, ext in sections.items() +) + +out += """ +CONFIG += debug_and_release static +QT += svg printsupport +QMAKE_CXXFLAGS_DEBUG = " -O0 -g" + +macx{ + ICON = ../images/icon.icns + CONFIG += x86 + LIBS += -llapack -lblas + QMAKE_INFO_PLIST = ../chemvp.plist +} + +win32{ + RC_FILE = ../images/icon.rc + CONFIG -= debug + QMAKE_CXXFLAGS_RELEASE -= -mthreads + QMAKE_LFLAGS_RELEASE -= -mthreads +}""" + +with open(filename, "w") as f: + f.write(out) + +qmake_flags = "-spec macx-g++" if len(sys.argv) > 1 and sys.argv[1] == "mac" else "" + +check_call(f"qmake {qmake_flags} {filename}".split()) +check_call(f"time nice make -j {N_PROCS}".split()) diff --git a/images/addarrow.png b/images/addarrow.png old mode 100755 new mode 100644 index 7d69644..1fc7711 Binary files a/images/addarrow.png and b/images/addarrow.png differ diff --git a/images/addbond.png b/images/addbond.png old mode 100755 new mode 100644 index 0cd2914..4ceb7a2 Binary files a/images/addbond.png and b/images/addbond.png differ diff --git a/images/addtext.png b/images/addtext.png old mode 100755 new mode 100644 index d71f4e0..4d491f6 Binary files a/images/addtext.png and b/images/addtext.png differ diff --git a/images/boldtext.png b/images/boldtext.png old mode 100755 new mode 100644 index 373dda5..c55313f Binary files a/images/boldtext.png and b/images/boldtext.png differ diff --git a/images/cursor_move.png b/images/cursor_move.png old mode 100755 new mode 100644 index 2f86d07..11ca1f1 Binary files a/images/cursor_move.png and b/images/cursor_move.png differ diff --git a/images/cursor_rotate.png b/images/cursor_rotate.png old mode 100755 new mode 100644 index a197a7b..a28c5e4 Binary files a/images/cursor_rotate.png and b/images/cursor_rotate.png differ diff --git a/images/cursor_select.png b/images/cursor_select.png old mode 100755 new mode 100644 index 14a1ab5..9ce480f Binary files a/images/cursor_select.png and b/images/cursor_select.png differ diff --git a/images/delete.png b/images/delete.png old mode 100755 new mode 100644 index df2a147..eeeb671 Binary files a/images/delete.png and b/images/delete.png differ diff --git a/images/dmg_background.png b/images/dmg_background.png old mode 100755 new mode 100644 index 0afcf50..cface3d Binary files a/images/dmg_background.png and b/images/dmg_background.png differ diff --git a/images/exit.png b/images/exit.png old mode 100755 new mode 100644 index 5979044..fc38bcc Binary files a/images/exit.png and b/images/exit.png differ diff --git a/images/icon.png b/images/icon.png old mode 100755 new mode 100644 index 94ee005..218302c Binary files a/images/icon.png and b/images/icon.png differ diff --git a/images/italictext.png b/images/italictext.png old mode 100755 new mode 100644 index c295ada..b530281 Binary files a/images/italictext.png and b/images/italictext.png differ diff --git a/images/open.png b/images/open.png old mode 100755 new mode 100644 index b0e8d2e..ed4ec74 Binary files a/images/open.png and b/images/open.png differ diff --git a/images/redo.png b/images/redo.png old mode 100755 new mode 100644 index 27f6933..eaf852f Binary files a/images/redo.png and b/images/redo.png differ diff --git a/images/rotate.png b/images/rotate.png old mode 100755 new mode 100644 index ea79ca5..86db29a Binary files a/images/rotate.png and b/images/rotate.png differ diff --git a/images/save.png b/images/save.png old mode 100755 new mode 100644 index 88ae2cb..5b0e30b Binary files a/images/save.png and b/images/save.png differ diff --git a/images/saveas.png b/images/saveas.png old mode 100755 new mode 100644 index 01180ee..4d5fd57 Binary files a/images/saveas.png and b/images/saveas.png differ diff --git a/images/select.png b/images/select.png old mode 100755 new mode 100644 index 829baca..d2aca83 Binary files a/images/select.png and b/images/select.png differ diff --git a/images/underlinetext.png b/images/underlinetext.png old mode 100755 new mode 100644 index bc9d28f..8f5c503 Binary files a/images/underlinetext.png and b/images/underlinetext.png differ diff --git a/images/undo.png b/images/undo.png old mode 100755 new mode 100644 index 3eee75e..600e9a0 Binary files a/images/undo.png and b/images/undo.png differ diff --git a/qmake_script b/qmake_script deleted file mode 100755 index 6750129..0000000 --- a/qmake_script +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/ruby - -# Ignore this for now... -FolderName = File.basename(Dir.getwd) -#FileName = FolderName + ".pro" -# Just call everything chemvp -FileName = "cheMVP.pro" - -QMakeFile = File.new(FileName, "w") -SourceArray = Dir["../src/*.{cc,cpp}"].reject{|f| f.match(/^moc_/) || f.match(/^qrc_/)} -ResourceArray = Dir["../src/*.{qrc}"] -QMakeFile.puts "SOURCES = " + SourceArray.join(" \\ \n") -QMakeFile.puts "HEADERS = " + Dir["../src/*.h"].join(" \\ \n") -if(ResourceArray.size) - QMakeFile.puts "RESOURCES = " + ResourceArray.join(" \\ \n") -end -QMakeFile.puts "\nCONFIG += debug_and_release static" -QMakeFile.puts "QT += svg printsupport" -QMakeFile.puts "QMAKE_CXXFLAGS_DEBUG = \" -O0 -g\"" -QMakeFile.puts "\nmacx{" -QMakeFile.puts " ICON = ../images/icon.icns\n" -QMakeFile.puts " CONFIG += x86\n" -QMakeFile.puts " LIBS += -llapack -lblas\n" -QMakeFile.puts " QMAKE_INFO_PLIST = ../chemvp.plist" -QMakeFile.puts "}" -QMakeFile.puts "\nwin32{" -QMakeFile.puts " RC_FILE = ../images/icon.rc" -QMakeFile.puts " CONFIG -= debug" -QMakeFile.puts " QMAKE_CXXFLAGS_RELEASE -= -mthreads" -QMakeFile.puts " QMAKE_LFLAGS_RELEASE -= -mthreads" -QMakeFile.puts "}" -QMakeFile.close - -#`qmake -spec macx-g++ #{FileName}` -`qmake #{FileName}` diff --git a/src/angle.cpp b/src/angle.cpp index e2e1cc1..759a344 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -60,9 +60,9 @@ void Angle::updatePosition() double r1 = sqrt(dX1 * dX1 + dY1 * dY1 + dZ1 * dZ1); double cosTheta1 = dZ1 / r1; double sinTheta1 = sin(acos(cosTheta1)); - double phi1 = (norm1 == 0.0 ? 0.0 : acos(dY1 / norm1)); - if (dX1 < 0.0) { - phi1 = 2.0 * PI - phi1; + double phi1 = (norm1 < 1e-9 ? 0 : acos(dY1 / norm1)); + if (dX1 < 0) { + phi1 = 2 * PI - phi1; } // The angle between bond 2 and the vertical double dX3 = myEndAtom->pos().x() - myCenterAtom->pos().x(); @@ -72,9 +72,9 @@ void Angle::updatePosition() double r3 = sqrt(dX3 * dX3 + dY3 * dY3 + dZ3 * dZ3); double cosTheta3 = dZ3 / r3; double sinTheta3 = sin(acos(cosTheta3)); - double phi3 = (norm3 == 0.0 ? 0.0 : acos(dY3 / norm3)); - if (dX3 < 0.0) { - phi3 = 2.0 * PI - phi3; + double phi3 = (norm3 < 1e-9 ? 0 : acos(dY3 / norm3)); + if (dX3 < 0) { + phi3 = 2 * PI - phi3; } double radius = myCenterAtom->effectiveRadius() + 0.2 * _info->scaleFactor(); @@ -92,19 +92,19 @@ void Angle::updatePosition() // The vectors from atom2 to the points startPos and endPos are normalized to radius by // construction. The // sum of them is the midpoint, but it must be renormalized to radius - double scale = radius / sqrt(pow(bond1Pos.x() + bond2Pos.x() - 2.0 * xRef, 2.0) + - pow(bond1Pos.y() + bond2Pos.y() - 2.0 * yRef, 2.0) + - pow(bond1Z + bond2Z - 2.0 * zRef, 2.0)); + double scale = radius / sqrt(pow(bond1Pos.x() + bond2Pos.x() - 2 * xRef, 2) + + pow(bond1Pos.y() + bond2Pos.y() - 2 * yRef, 2) + + pow(bond1Z + bond2Z - 2 * zRef, 2)); // This is the midpoint on the arc from p1 to p3 - double zMP = zRef + scale * (bond1Z + bond2Z - 2.0 * zRef); - QPointF MP(xRef + scale * (bond1Pos.x() + bond2Pos.x() - 2.0 * xRef), - yRef + scale * (bond1Pos.y() + bond2Pos.y() - 2.0 * yRef)); + double zMP = zRef + scale * (bond1Z + bond2Z - 2 * zRef); + QPointF MP(xRef + scale * (bond1Pos.x() + bond2Pos.x() - 2 * xRef), + yRef + scale * (bond1Pos.y() + bond2Pos.y() - 2 * yRef)); // Time to account for the angle markers not touching the bonds double fraction = atan(ANGLE_MARKER_OFFSET); - scale = radius / sqrt(pow(bond1Pos.x() - xRef + fraction * (bond2Pos.x() - xRef), 2.0) + - pow(bond1Pos.y() - yRef + fraction * (bond2Pos.y() - yRef), 2.0) + - pow(bond1Z - zRef + fraction * (bond2Z - zRef), 2.0)); + scale = radius / sqrt(pow(bond1Pos.x() - xRef + fraction * (bond2Pos.x() - xRef), 2) + + pow(bond1Pos.y() - yRef + fraction * (bond2Pos.y() - yRef), 2) + + pow(bond1Z - zRef + fraction * (bond2Z - zRef), 2)); QPointF startPos(xRef + scale * (bond1Pos.x() - xRef + fraction * (bond2Pos.x() - xRef)), yRef + scale * (bond1Pos.y() - yRef + fraction * (bond2Pos.y() - yRef))); QPointF endPos(xRef + scale * (bond2Pos.x() - xRef + fraction * (bond1Pos.x() - xRef)), @@ -113,23 +113,23 @@ void Angle::updatePosition() double endZ = zRef + scale * (bond2Z - zRef + fraction * (bond1Z - zRef)); // Redefine this to be the normalization for the quarter and three-quarter point vectors - scale = radius / sqrt(pow(MP.x() + startPos.x() - 2.0 * xRef, 2.0) + - pow(MP.y() + startPos.y() - 2.0 * yRef, 2.0) + - pow(zMP + startZ - 2.0 * zRef, 2.0)); + scale = radius / sqrt(pow(MP.x() + startPos.x() - 2 * xRef, 2) + + pow(MP.y() + startPos.y() - 2 * yRef, 2) + + pow(zMP + startZ - 2 * zRef, 2)); // This will be the quarter point along the arc - QPointF QP1(xRef + scale * (startPos.x() + MP.x() - 2.0 * xRef), - yRef + scale * (startPos.y() + MP.y() - 2.0 * yRef)); + QPointF QP1(xRef + scale * (startPos.x() + MP.x() - 2 * xRef), + yRef + scale * (startPos.y() + MP.y() - 2 * yRef)); // This will be the three-quarter point along the arc - QPointF QP3(xRef + scale * (endPos.x() + MP.x() - 2.0 * xRef), - yRef + scale * (endPos.y() + MP.y() - 2.0 * yRef)); + QPointF QP3(xRef + scale * (endPos.x() + MP.x() - 2 * xRef), + yRef + scale * (endPos.y() + MP.y() - 2 * yRef)); myMarker1->setZValue(startZ); myMarker2->setZValue(endZ); // This is the interpolation formula to force the curve through QP1 - QPointF guidePoint1 = 2.0 * QP1 - 0.5 * (startPos + MP); + QPointF guidePoint1 = 2 * QP1 - (startPos + MP)/2; // This is the interpolation formula to force the curve through QP3 - QPointF guidePoint3 = 2.0 * QP3 - 0.5 * (endPos + MP); + QPointF guidePoint3 = 2 * QP3 - (endPos + MP)/2; QPainterPath path1(startPos); path1.quadTo(guidePoint1, MP); @@ -144,9 +144,9 @@ void Angle::updatePosition() if (myLabel != 0) { QPointF labelPos; labelPos.setX(xRef + myLabel->dX() + - 1.5 * scale * (endPos.x() + startPos.x() - 2.0 * xRef)); + 1.5 * scale * (endPos.x() + startPos.x() - 2 * xRef)); labelPos.setY(yRef + myLabel->dY() + - 1.5 * scale * (endPos.y() + startPos.y() - 2.0 * yRef)); + 1.5 * scale * (endPos.y() + startPos.y() - 2 * yRef)); myLabel->setPos(labelPos); } } diff --git a/src/application.cpp b/src/application.cpp index f10cf40..0cbdb75 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -12,10 +12,10 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) bool Application::event(QEvent *event) { switch (event->type()) { - case QEvent::FileOpen: - return loadFile(static_cast(event)->file()); - default: - return QApplication::event(event); + case QEvent::FileOpen: + return loadFile(static_cast(event)->file()); + default: + return QApplication::event(event); } } diff --git a/src/arrow.cpp b/src/arrow.cpp index 403cc6c..7fbbcd2 100644 --- a/src/arrow.cpp +++ b/src/arrow.cpp @@ -10,7 +10,7 @@ DragBox::DragBox(double x, double y, DrawingInfo *info, QGraphicsItem *parent) setAcceptHoverEvents(true); setZValue(1001.0); double dimension = 0.1 * drawingInfo->scaleFactor(); - setRect(-dimension / 2.0, -dimension / 2.0, dimension, dimension); + setRect(-dimension / 2, -dimension / 2, dimension, dimension); setPos(myDX + drawingInfo->dX(), myDY + drawingInfo->dY()); } @@ -44,8 +44,7 @@ void DragBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q { Q_UNUSED(option); Q_UNUSED(widget); - if (!hoverOver) - { + if (!hoverOver) { return; } myPen.setWidthF(0.001 * drawingInfo->scaleFactor()); @@ -59,12 +58,12 @@ Arrow::Arrow(double x, double y, DrawingInfo *info, QGraphicsItem *parent) { setFlag(QGraphicsItem::ItemIsSelectable, true); setAcceptHoverEvents(true); - setZValue(1000.0); + setZValue(1000); myStartBox = new DragBox(x, y, drawingInfo); myEndBox = new DragBox(x, y, drawingInfo); setThickness(DEFAULT_ARROW_THICKNESS); // So that the width of the line is correct when determining the shape - myPen.setWidth((int)(3.0 * effectiveWidth)); + myPen.setWidth((int)(3 * effectiveWidth)); setPen(myPen); } @@ -77,7 +76,7 @@ void Arrow::updatePosition(double x, double y) void Arrow::updatePosition() { - double angle = (line().length() == 0.0 ? 0.0 : acos(line().dx() / line().length())); + double angle = (line().length() < 1e-9 ? 0 : acos(line().dx() / line().length())); double arrowSize = 0.08 * drawingInfo->scaleFactor(); // Update the arrow position myStartBox->setPos(drawingInfo->dX() + myStartBox->dX(), drawingInfo->dY() + myStartBox->dY()); @@ -87,23 +86,22 @@ void Arrow::updatePosition() myEndBox->scenePos().x(), myEndBox->scenePos().y())); - if (line().dy() >= 0) - { - angle = (PI * 2) - angle; + if (line().dy() >= 0) { + angle = (2 * PI) - angle; } QPointF arrowP1 = - line().p2() - QPointF(sin(angle + PI / 3.0) * arrowSize, cos(angle + PI / 3.0) * arrowSize); - QPointF arrowP2 = line().p2() - QPointF(sin(angle + PI - PI / 3.0) * arrowSize, - cos(angle + PI - PI / 3.0) * arrowSize); + line().p2() - QPointF(sin(angle + PI / 3) * arrowSize, cos(angle + PI / 3) * arrowSize); + QPointF arrowP2 = line().p2() - QPointF(sin(angle + PI - PI / 3) * arrowSize, + cos(angle + PI - PI / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p2() << arrowP1 << arrowP2; // Stop the line at the butt of the arrowhead, not the tip if (line().length() > arrowSize) { setLine(QLineF(line().p1(), - line().p2() + QPointF(-cos(angle) * arrowSize * sqrt(3.0) / 2.0, - sin(angle) * arrowSize * sqrt(3.0) / 2.0))); + line().p2() + QPointF(-cos(angle) * arrowSize * sqrt(3) / 2, + sin(angle) * arrowSize * sqrt(3) / 2))); } // In case the scale factor changed, recompute the thickness setThickness(myThickness); @@ -113,7 +111,7 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi { Q_UNUSED(option); Q_UNUSED(widget); - myPen.setWidthF(hoverOver ? 2.0 * effectiveWidth : effectiveWidth); + myPen.setWidthF(hoverOver ? 2 * effectiveWidth : effectiveWidth); myPen.setColor(Qt::black); // Draw the line painter->setPen(myPen); @@ -124,7 +122,7 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi painter->setPen(myPen); painter->drawPolygon(arrowHead); if (isSelected()) { - myPen.setWidthF(hoverOver ? 10.0 * effectiveWidth : effectiveWidth); + myPen.setWidthF(hoverOver ? 10 * effectiveWidth : effectiveWidth); myPen.setColor(SELECTED_COLOR); painter->setPen(myPen); painter->drawLine(line()); diff --git a/src/atom.cpp b/src/atom.cpp index 0082f6c..e4fa6fc 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -20,7 +20,7 @@ Atom::Atom(QString element, DrawingInfo *i, QGraphicsItem *parent) myRadius = labelToVdwRadius.value(mySymbol).toDouble(); } myMass = labelToMass.value(mySymbol).toDouble(); - if (myMass == 0.0 && mySymbol != "X") { + if (myMass < 1e-9 && mySymbol != "X") { QString errorMessage = "I don't know the mass of the atom " + mySymbol; error(errorMessage, __FILE__, __LINE__); return; @@ -30,9 +30,9 @@ Atom::Atom(QString element, DrawingInfo *i, QGraphicsItem *parent) setAcceptHoverEvents(true); setAcceptDrops(true); myEffectiveRadius = - _info->scaleFactor() * (1.0 + zValue() * _info->perspective()) * myRadius * myScaleFactor; + _info->scaleFactor() * (1 + zValue() * _info->perspective()) * myRadius * myScaleFactor; setRect(QRectF( - -myEffectiveRadius, -myEffectiveRadius, 2.0 * myEffectiveRadius, 2.0 * myEffectiveRadius)); + -myEffectiveRadius, -myEffectiveRadius, 2 * myEffectiveRadius, 2 * myEffectiveRadius)); } void Atom::setLabel(const QString &text) @@ -99,7 +99,7 @@ QRectF Atom::boundingRect() const void Atom::computeRadius() { myEffectiveRadius = - _info->scaleFactor() * (1.0 + zValue() * _info->perspective()) * myRadius * myScaleFactor; + _info->scaleFactor() * (1 + zValue() * _info->perspective()) * myRadius * myScaleFactor; } void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -110,7 +110,7 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid // The myEffectiveRadius changes on zooming/rotation so we must always update it setRect(QRectF( - -myEffectiveRadius, -myEffectiveRadius, 2.0 * myEffectiveRadius, 2.0 * myEffectiveRadius)); + -myEffectiveRadius, -myEffectiveRadius, 2 * myEffectiveRadius, 2 * myEffectiveRadius)); // If the item is selected, use a lighter color for the filling QPen linestyle; // If we're hovering over the item, use thicker lines @@ -119,11 +119,11 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid painter->setPen(linestyle); // The outline of the atom is a little bit too diffuse, here's another more diffuse circle // that accounts for the width of the line so that the gradient and fogging options look pretty - float lineWidth = linestyle.widthF() / 2.0; + float lineWidth = linestyle.widthF() / 2; QRectF fillRect(-myEffectiveRadius - lineWidth, -myEffectiveRadius - lineWidth, - 2.0 * myEffectiveRadius + 2.0 * lineWidth, - 2.0 * myEffectiveRadius + 2.0 * lineWidth); + 2 * myEffectiveRadius + 2 * lineWidth, + 2 * myEffectiveRadius + 2 * lineWidth); // The circle defnining the atom if (_info->getDrawingStyle() == DrawingInfo::Gradient) { @@ -131,8 +131,8 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid QRadialGradient gradient(QPointF(0.0, 0.0), myEffectiveRadius, QPointF(myEffectiveRadius / 2.1, -myEffectiveRadius / 2.1)); - gradient.setColorAt(0.0, Qt::white); - gradient.setColorAt(1.0, fill_color); + gradient.setColorAt(0, Qt::white); + gradient.setColorAt(1, fill_color); gradient.setSpread(QGradient::RepeatSpread); // PDF looks bad when rendering gradient - here's a workaround painter->setPen(Qt::transparent); @@ -150,13 +150,13 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid if (myFontSizeStyle != LargeLabel) { // These boxes define the path of the two arcs QRectF h_line_box(-myEffectiveRadius, - -myEffectiveRadius / 2.0, - 2.0 * myEffectiveRadius, + -myEffectiveRadius / 2, + 2 * myEffectiveRadius, myEffectiveRadius); - QRectF v_line_box(-myEffectiveRadius / 2.0, + QRectF v_line_box(-myEffectiveRadius / 2, -myEffectiveRadius, myEffectiveRadius, - 2.0 * myEffectiveRadius); + 2 * myEffectiveRadius); // 2880 is 180 degrees: QT wants angles in 1/16ths of a degree painter->drawArc(h_line_box, 0, -2880); // The direction of the vertical arc depends on the style @@ -198,12 +198,9 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid setLabelFontSize(myFontSize); QFontMetricsF labelFM(_info->getAtomLabelFont()); // TODO check these offsets. I think there's a bug in the height reported by fontmetrics - QPointF labelPos; - if (myFontSizeStyle == LargeLabel) { - labelPos = QPointF(-labelFM.width(myLabel) / 2.0, labelFM.height() / 3.0); - } else { - labelPos = QPointF(-labelFM.width(myLabel) / 2.0, labelFM.height() / 3.5); - } + double height = (myFontSizeStyle == LargeLabel ? labelFM.height() / 3.5 : labelFM.height() / 3); + QPointF labelPos = QPointF(-labelFM.width(myLabel) / 2, height); + painter->setPen(_info->getAtomTextColor()); painter->setBrush(_info->getAtomTextColor()); painter->setFont(_info->getAtomLabelFont()); @@ -211,11 +208,11 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid // If there's a subscript to be drawn, do it if (myLabelSubscript.size()) { QFont subscriptFont(_info->getAtomLabelFont().family(), - (int)(_info->getAtomLabelFont().pointSizeF() / 2.0)); + (int)(_info->getAtomLabelFont().pointSizeF() / 2)); painter->setFont(subscriptFont); qreal hOffset = labelFM.width(myLabel); QFontMetricsF subscriptFM(subscriptFont); - qreal vOffset = subscriptFM.height() / 3.0; + qreal vOffset = subscriptFM.height() / 3; painter->drawText(labelPos + QPointF(hOffset, vOffset), myLabelSubscript); } @@ -223,14 +220,14 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid // If there's a superscript to be drawn, do it if (myLabelSuperscript.size()) { QFont superscriptFont(_info->getAtomLabelFont().family(), - (int)(_info->getAtomLabelFont().pointSizeF() / 2.0)); + (int)(_info->getAtomLabelFont().pointSizeF() / 2)); painter->setFont(superscriptFont); qreal hOffset = labelFM.width(myLabel); qreal vOffset2 = labelFM.height(); QFontMetricsF superscriptFM(superscriptFont); - qreal vOffset = superscriptFM.height() / 3.0; + qreal vOffset = superscriptFM.height() / 3; - painter->drawText(labelPos + QPointF(hOffset, -vOffset2 + 2.0 * vOffset), + painter->drawText(labelPos + QPointF(hOffset, -vOffset2 + 2 * vOffset), myLabelSuperscript); } @@ -243,7 +240,7 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid if (_info->getUseFogging()) { double dZ = _info->maxZ() - _info->minZ(); double thisZ = fabs(myZ - _info->maxZ()); - double opacity = (dZ > TINY ? 2.56 * (_info->getFoggingScale()) * (thisZ / dZ) : 0.0); + double opacity = (dZ > TINY ? 2.56 * (_info->getFoggingScale()) * (thisZ / dZ) : 0); opacity = (opacity < 0 ? 0 : opacity); opacity = (opacity > 255 ? 255 : opacity); painter->setPen(Qt::transparent); @@ -254,8 +251,7 @@ void Atom::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid double Atom::bondLength(Atom *s, Atom *e) { - return ( - sqrt(pow(s->x() - e->x(), 2.0) + pow(s->y() - e->y(), 2.0) + pow(s->z() - e->z(), 2.0))); + return sqrt(pow(s->x() - e->x(), 2) + pow(s->y() - e->y(), 2) + pow(s->z() - e->z(), 2)); } void Atom::fillLabelToVdwRadiusMap() diff --git a/src/atom.h b/src/atom.h index fe1e9b3..fa48898 100644 --- a/src/atom.h +++ b/src/atom.h @@ -100,7 +100,7 @@ class Atom : public QGraphicsEllipseItem void setLabelFontSize(int val) { myFontSize = val; - _info->getAtomLabelFont().setPointSizeF(double(val) * myEffectiveRadius / 20.0); + _info->getAtomLabelFont().setPointSizeF(double(val) * myEffectiveRadius / 20); } void setScaleFactor(double val) { diff --git a/src/bond.cpp b/src/bond.cpp index e19134e..000e5d3 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -137,7 +137,7 @@ void Bond::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid if (_info->getUseFogging()) { double dZ = _info->maxBondZ() - _info->minBondZ(); double thisZ = fabs(computeMidZ() - _info->maxBondZ()); - double opacity = (dZ > TINY ? 2.56 * (_info->getFoggingScale()) * (thisZ / dZ) : 0.0); + double opacity = (dZ > TINY ? 2.56 * (_info->getFoggingScale()) * (thisZ / dZ) : 0); opacity = (opacity < 0 ? 0 : opacity); opacity = (opacity > 255 ? 255 : opacity); myPen.setColor(QColor(255, 255, 255, opacity)); diff --git a/src/drawingcanvas.cpp b/src/drawingcanvas.cpp index 0574165..e6fa719 100644 --- a/src/drawingcanvas.cpp +++ b/src/drawingcanvas.cpp @@ -384,7 +384,7 @@ void DrawingCanvas::determineRotationAngles() printf("Stored Rotations: %6.4f %6.4f %6.4f\n", xRot, yRot, zRot); // Determine the corresponding euler angles x->y->z double theta, phi, omega; - if (!(abs(rotationMatrix[2][0]) - 1E-8 < 1 && abs(rotationMatrix[2][0] + 1E-8 > 1))) { + if (!(abs(rotationMatrix[2][0]) - 1E-8 < 1 && abs(rotationMatrix[2][0]) + 1E-8 > 1)) { double theta1 = -asin(rotationMatrix[2][0]); double theta2 = PI - theta1; double omega1 = diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 31cb79e..8541838 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -120,7 +120,8 @@ void MainWindow::setLabelBoldness(bool bold) foreach (QGraphicsItem *item, canvas->items()) { if (ITEM_IS_LABEL) { Label *label = dynamic_cast