src/MainWindow.cc

changeset 653
a9966d51ebf1
parent 646
1ccb092cebed
equal deleted inserted replaced
652:5d37b2f2ae16 653:a9966d51ebf1
62 extern_cfg (Bool, gl_colorbfc); 62 extern_cfg (Bool, gl_colorbfc);
63 extern_cfg (Bool, gl_drawangles); 63 extern_cfg (Bool, gl_drawangles);
64 64
65 // ============================================================================= 65 // =============================================================================
66 // 66 //
67 67 MainWindow::MainWindow (QWidget* parent, Qt::WindowFlags flags) :
68 MainWindow::MainWindow (QWidget* parent, Qt::WindowFlags flags) 68 QMainWindow (parent, flags)
69 { 69 {
70 g_win = this; 70 g_win = this;
71 ui = new Ui_LDForgeUI; 71 ui = new Ui_LDForgeUI;
72 ui->setupUi (this); 72 ui->setupUi (this);
73 m_updatingTabs = false; 73 m_updatingTabs = false;
809 { 809 {
810 return (QPixmap (format (":/icons/%1.png", iconName))); 810 return (QPixmap (format (":/icons/%1.png", iconName)));
811 } 811 }
812 812
813 // ============================================================================= 813 // =============================================================================
814 bool confirm (QString msg) 814 //
815 bool confirm (const QString& message)
815 { 816 {
816 return confirm (MainWindow::tr ("Confirm"), message); 817 return confirm (MainWindow::tr ("Confirm"), message);
817 } 818 }
818 819
819 bool confirm (QString title, QString msg) 820 // =============================================================================
820 { 821 //
821 return QMessageBox::question (g_win, title, messag, 822 bool confirm (const QString& title, const QString& message)
823 {
824 return QMessageBox::question (g_win, title, message,
822 (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes; 825 (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes;
823 } 826 }
824 827
825 // ============================================================================= 828 // =============================================================================
826 void critical (QString msg) 829 //
830 void critical (const QString& message)
827 { 831 {
828 QMessageBox::critical (g_win, MainWindow::tr ("Error"), message, 832 QMessageBox::critical (g_win, MainWindow::tr ("Error"), message,
829 (QMessageBox::Close), QMessageBox::Close); 833 (QMessageBox::Close), QMessageBox::Close);
830 } 834 }
831 835
832 // ============================================================================= 836 // =============================================================================
837 //
833 QIcon makeColorIcon (LDColor* colinfo, const int size) 838 QIcon makeColorIcon (LDColor* colinfo, const int size)
834 { 839 {
835 // Create an image object and link a painter to it. 840 // Create an image object and link a painter to it.
836 QImage img (size, size, QImage::Format_ARGB32); 841 QImage img (size, size, QImage::Format_ARGB32);
837 QPainter paint (&img); 842 QPainter paint (&img);
854 paint.fillRect (QRect (1, 1, size - 2, size - 2), col); 859 paint.fillRect (QRect (1, 1, size - 2, size - 2), col);
855 return QIcon (QPixmap::fromImage (img)); 860 return QIcon (QPixmap::fromImage (img));
856 } 861 }
857 862
858 // ============================================================================= 863 // =============================================================================
864 //
859 void makeColorComboBox (QComboBox* box) 865 void makeColorComboBox (QComboBox* box)
860 { 866 {
861 std::map<int, int> counts; 867 std::map<int, int> counts;
862 868
863 for (LDObject* obj : getCurrentDocument()->objects()) 869 for (LDObject* obj : getCurrentDocument()->objects())
886 892
887 ++row; 893 ++row;
888 } 894 }
889 } 895 }
890 896
897 // =============================================================================
898 //
891 void MainWindow::updateDocumentList() 899 void MainWindow::updateDocumentList()
892 { 900 {
893 m_updatingTabs = true; 901 m_updatingTabs = true;
894 902
895 while (m_tabs->count() > 0) 903 while (m_tabs->count() > 0)
908 } 916 }
909 917
910 m_updatingTabs = false; 918 m_updatingTabs = false;
911 } 919 }
912 920
921 // =============================================================================
922 //
913 void MainWindow::updateDocumentListItem (LDDocument* doc) 923 void MainWindow::updateDocumentListItem (LDDocument* doc)
914 { 924 {
915 bool oldUpdatingTabs = m_updatingTabs; 925 bool oldUpdatingTabs = m_updatingTabs;
916 m_updatingTabs = true; 926 m_updatingTabs = true;
917 927
934 m_tabs->setTabIcon (doc->tabIndex(), doc->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); 944 m_tabs->setTabIcon (doc->tabIndex(), doc->hasUnsavedChanges() ? getIcon ("file-save") : QIcon());
935 m_updatingTabs = oldUpdatingTabs; 945 m_updatingTabs = oldUpdatingTabs;
936 } 946 }
937 947
938 // ============================================================================= 948 // =============================================================================
949 //
939 // A file is selected from the list of files on the left of the screen. Find out 950 // A file is selected from the list of files on the left of the screen. Find out
940 // which file was picked and change to it. 951 // which file was picked and change to it.
952 //
941 void MainWindow::changeCurrentFile() 953 void MainWindow::changeCurrentFile()
942 { 954 {
943 if (m_updatingTabs) 955 if (m_updatingTabs)
944 return; 956 return;
945 957
962 return; 974 return;
963 975
964 LDDocument::setCurrent (f); 976 LDDocument::setCurrent (f);
965 } 977 }
966 978
979 // =============================================================================
980 //
967 void MainWindow::refreshObjectList() 981 void MainWindow::refreshObjectList()
968 { 982 {
969 #if 0 983 #if 0
970 ui->objectList->clear(); 984 ui->objectList->clear();
971 LDDocument* f = getCurrentDocument(); 985 LDDocument* f = getCurrentDocument();
976 #endif 990 #endif
977 991
978 buildObjList(); 992 buildObjList();
979 } 993 }
980 994
995 // =============================================================================
996 //
981 void MainWindow::updateActions() 997 void MainWindow::updateActions()
982 { 998 {
983 History* his = getCurrentDocument()->history(); 999 History* his = getCurrentDocument()->history();
984 int pos = his->position(); 1000 int pos = his->position();
985 ui->actionUndo->setEnabled (pos != -1); 1001 ui->actionUndo->setEnabled (pos != -1);
987 ui->actionAxes->setChecked (gl_axes); 1003 ui->actionAxes->setChecked (gl_axes);
988 ui->actionBFCView->setChecked (gl_colorbfc); 1004 ui->actionBFCView->setChecked (gl_colorbfc);
989 ui->actionDrawAngles->setChecked (gl_drawangles); 1005 ui->actionDrawAngles->setChecked (gl_drawangles);
990 } 1006 }
991 1007
1008 // =============================================================================
1009 //
992 QImage imageFromScreencap (uchar* data, int w, int h) 1010 QImage imageFromScreencap (uchar* data, int w, int h)
993 { 1011 {
994 // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. 1012 // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well.
995 return QImage (data, w, h, QImage::Format_ARGB32).rgbSwapped().mirrored(); 1013 return QImage (data, w, h, QImage::Format_ARGB32).rgbSwapped().mirrored();
996 } 1014 }
999 // 1017 //
1000 LDQuickColor::LDQuickColor (LDColor* color, QToolButton* toolButton) : 1018 LDQuickColor::LDQuickColor (LDColor* color, QToolButton* toolButton) :
1001 m_color (color), 1019 m_color (color),
1002 m_toolButton (toolButton) {} 1020 m_toolButton (toolButton) {}
1003 1021
1022 // =============================================================================
1023 //
1004 LDQuickColor LDQuickColor::getSeparator() 1024 LDQuickColor LDQuickColor::getSeparator()
1005 { 1025 {
1006 return LDQuickColor (null, null); 1026 return LDQuickColor (null, null);
1007 } 1027 }
1008 1028
1029 // =============================================================================
1030 //
1009 bool LDQuickColor::isSeparator() const 1031 bool LDQuickColor::isSeparator() const
1010 { 1032 {
1011 return color() == null; 1033 return color() == null;
1012 } 1034 }

mercurial