Index: src/CoordinateData.cpp ================================================================== --- src/CoordinateData.cpp +++ src/CoordinateData.cpp @@ -6,44 +6,56 @@ // CLASS: coordinateData // /////////////////////////// //================================================================== coordinateData::coordinateData() { - initCoordinates(); - initGlyphs(); + createCoordinates(); + createGlyphs(); } //------------------------------------------------------------------ coordinateData::coordinateData (const QString &_code, bool isCoordinate) { - initCoordinates(); - initGlyphs(); + createCoordinates(); + createGlyphs(); if ( isCoordinate == true ) coordinates = _code; else glyph_code = _code; +} +//------------------------------------------------------------------ +//////////////// +// DESTRUCTOR // +//////////////// +//------------------------------------------------------------------ +coordinateData::~coordinateData() +{ + coordinates.clear(); + glyph_code.clear(); + error_info.clear(); + portal = -1; } //------------------------------------------------------------------ /////////////////////// // COPY CONSTRUCTORS // /////////////////////// //------------------------------------------------------------------ coordinateData::coordinateData (const coordinateData &other) { - initCoordinates(); - initGlyphs(); + createCoordinates(); + createGlyphs(); portal = other.portal; coordinates = other.coordinates; glyph_code = other.glyph_code; error_info = other.error_info; } //------------------------------------------------------------------ coordinateData::coordinateData (coordinateData &other) { - initCoordinates(); - initGlyphs(); + createCoordinates(); + createGlyphs(); portal = other.portal; coordinates = other.coordinates; glyph_code = other.glyph_code; error_info = other.error_info; @@ -68,17 +80,17 @@ } //------------------------------------------------------------------ coordinateData &coordinateData::operator = (coordinateData &other) { // Handle self-assignment - if ( this != &other ) - { - portal = other.portal; - coordinates = other.coordinates; - glyph_code = other.glyph_code; - error_info = other.error_info; - } + if ( this == &other ) + return (*this); + + portal = other.portal; + coordinates = other.coordinates; + glyph_code = other.glyph_code; + error_info = other.error_info; return (*this); } //------------------------------------------------------------------ ////////////////////// @@ -85,32 +97,30 @@ // PUBLIC FUNCTIONS // ////////////////////// //------------------------------------------------------------------ QString coordinateData::getGlyphCode() const { - return (glyph_code.toUpper()); + return (glyph_code.toUpper()); } //------------------------------------------------------------------ QString coordinateData::getCoordinate() const { - return (coordinates.toUpper()); + return (coordinates.toUpper()); } //------------------------------------------------------------------ QString coordinateData::getCoordinates() const { - return (getCoordinate()); + return (getCoordinate()); } //------------------------------------------------------------------ QStringList coordinateData::getErrorInfo() const { - return (error_info); + return (error_info); } //------------------------------------------------------------------ QString coordinateData::showErrorInfo() const { - // Ideally this function should never be called unless - // there is something to display from error_info. QString result = QString(); if ( error_info.isEmpty() == false ) result.append( QString("[" + getErrorInfo().join("] [") + "]") ); @@ -117,41 +127,43 @@ return (result); } //------------------------------------------------------------------ QString coordinateData::toString() const { - QString result = QString(); - - if ( (coordinates.isEmpty() == true && glyph_code.isEmpty() == true) - || (coordinates == ":::" && glyph_code.isEmpty() == true) ) - result += "No coordinate data found." + QString ("\n"); - else - { - if ( coordinates.isEmpty() == false - && coordinates != ":::" ) - { - result += coordinates; - result += ", portal #" + QString::number (portal); - result += QString ("\n"); - } - - if ( glyph_code.isEmpty() == false ) - result += glyph_code + QString ("\n"); - } - - return (result); + QString result = QString(); + + if ( (coordinates.isEmpty() == true && glyph_code.isEmpty() == true) + || (coordinates == ":::" && glyph_code.isEmpty() == true) ) + { + result += "No coordinate data found." + QString ("\n"); + } + else + { + if ( coordinates.isEmpty() == false + && coordinates != ":::" ) + { + result += coordinates; + result += ", portal #" + QString::number (portal); + result += QString ("\n"); + } + + if ( glyph_code.isEmpty() == false ) + result += glyph_code + QString ("\n"); + } + + return (result); } //------------------------------------------------------------------ int coordinateData::getPortal() const { - return (portal); + return (portal); } //------------------------------------------------------------------ void coordinateData::setCoordinate (const QString &_code) { - if ( _code != coordinates ) - coordinates = _code; + if ( _code != coordinates ) + coordinates = _code; } //------------------------------------------------------------------ void coordinateData::setPortal (const int _number) { if ( is_valid_portal(_number) == true ) @@ -160,18 +172,18 @@ portal = 1; } //------------------------------------------------------------------ void coordinateData::setGlyphCode (const QString &_code) { - if ( _code != glyph_code ) - glyph_code = _code; + if ( _code != glyph_code ) + glyph_code = _code; } //------------------------------------------------------------------ void coordinateData::addToErrorInfo (const QString &error_data) { - if ( error_data.size() > 0 && error_data.at (0) != ':' ) - error_info += error_data; + if ( error_data.size() > 0 && error_data.at (0) != ':' ) + error_info += error_data; } //------------------------------------------------------------------ void coordinateData::reset() { clearCoordinates(); @@ -179,21 +191,22 @@ clearErrorInfo(); } //------------------------------------------------------------------ void coordinateData::clearCoordinates() { - coordinates.clear(); + coordinates.clear(); + portal = 1; } //------------------------------------------------------------------ void coordinateData::clearGlyphCode() { - glyph_code.clear(); + glyph_code.clear(); } //------------------------------------------------------------------ void coordinateData::clearErrorInfo() { - error_info.clear(); + error_info.clear(); } //------------------------------------------------------------------ void coordinateData::convertFromGlyph() { // Verify glyph code is valid hexadecimal and is valid @@ -214,10 +227,11 @@ */ QString coordinate_star, coordinate_x, coordinate_y, coordinate_z, temp_str, _glyph; int temp_value, offset = 0, temp_convert; _glyph.clear(); + // Iterate over the "strings" in _glyph, each of which is // a digit in the glyph code QStringList them_glyphs = glyph_code.split(""); for (int i = 0; i < them_glyphs.size(); i++) @@ -296,15 +310,15 @@ coordinate_star; coordinates = (QString(temp_str).toUpper()); } else { - // Add invalid code segments to element info + // Invalid glyph code entered. DO NOT COMPUTE coordinates. if ( temp_info.isEmpty() == false ) { for (int i = 0; i < temp_info.size(); i++) - addToErrorInfo (QString(temp_info.at(i))); + addToErrorInfo (QString(temp_info.at (i))); } else addToErrorInfo (glyph_code); } } @@ -421,29 +435,29 @@ //------------------------------------------------------------------ /////////////////////// // PRIVATE FUNCTIONS // /////////////////////// //------------------------------------------------------------------ -void coordinateData::initGlyphs() +void coordinateData::createGlyphs() { - glyph_code = QString(); + glyph_code = QString(); } //------------------------------------------------------------------ -void coordinateData::initCoordinates() +void coordinateData::createCoordinates() { - coordinates = QString(); - portal = int(1); - error_info = QStringList(); + coordinates = QString(); + portal = int(1); + error_info = QStringList(); } //------------------------------------------------------------------ ////////////////////// // FRIEND FUNCTIONS // ////////////////////// //------------------------------------------------------------------ QTextStream &operator >> (QTextStream &readInputInto, coordinateData &target) { - // Read into ins: + // Read the format: // coordinate portal glyph_code // // Error information will be determined upon conversion attempt. readInputInto >> target.coordinates >> target.portal; readInputInto >> target.glyph_code; @@ -451,108 +465,108 @@ return (readInputInto); } //------------------------------------------------------------------ QTextStream &operator << (QTextStream &outs, const coordinateData &the_data) { - outs << the_data.toString(); + outs << the_data.toString(); return (outs); } //------------------------------------------------------------------ QTextStream &operator << (QTextStream &outs, coordinateData &the_data) { - outs << the_data.toString(); + outs << the_data.toString(); return (outs); } //------------------------------------------------------------------ QDebug operator << (QDebug dbg, const coordinateData &the_data) { - QDebug outs = dbg.nospace(); - - outs << "[DEBUG][coordinateData]"; - - if ( (the_data.coordinates.isEmpty() == true - && the_data.glyph_code.isEmpty() == true) - || (the_data.coordinates == ":::" && the_data.glyph_code.isEmpty() == true) ) - { - outs << ": No coordinate data found.\n"; - } - else - { - if ( the_data.coordinates.size() > 0 - && the_data.coordinates != ":::" ) - { - outs << "\nCoordinates: "; - outs.noquote() << the_data.coordinates.toUpper(); - outs << ", portal #" << the_data.portal; - } - - if ( the_data.glyph_code.isEmpty() == false ) - { - outs << "\nGlyph code: "; - outs.noquote() << the_data.glyph_code.toUpper(); - } - - if ( the_data.error_info.isEmpty() == false ) - { - outs << "\ninvalid segments: "; - outs.noquote() << the_data.showErrorInfo(); - } - } - - return (dbg); + QDebug outs = dbg.nospace(); + + outs << "[DEBUG][coordinateData]"; + + if ( (the_data.coordinates.isEmpty() == true + && the_data.glyph_code.isEmpty() == true) + || (the_data.coordinates == ":::" && the_data.glyph_code.isEmpty() == true) ) + { + outs << ": No coordinate data found.\n"; + } + else + { + if ( the_data.coordinates.size() > 0 + && the_data.coordinates != ":::" ) + { + outs << "\nCoordinates: "; + outs.noquote() << the_data.coordinates.toUpper(); + outs << ", portal #" << the_data.portal; + } + + if ( the_data.glyph_code.isEmpty() == false ) + { + outs << "\nGlyph code: "; + outs.noquote() << the_data.glyph_code.toUpper(); + } + + if ( the_data.error_info.isEmpty() == false ) + { + outs << "\ninvalid segments: "; + outs.noquote() << the_data.showErrorInfo(); + } + } + + return (dbg); } //------------------------------------------------------------------ QDebug operator << (QDebug dbg, coordinateData &the_data) { - QDebug outs = dbg.nospace(); - - outs << "[DEBUG][coordinateData]"; - - if ( (the_data.coordinates.isEmpty() == true - && the_data.glyph_code.isEmpty() == true) - || (the_data.coordinates == ":::" && the_data.glyph_code.isEmpty() == true) ) - { - outs << ": No coordinate data found.\n"; - } - else - { - if ( the_data.coordinates.size() > 0 - && the_data.coordinates != ":::" ) - { - outs << "\nCoordinates: "; - outs.noquote() << the_data.coordinates.toUpper(); - outs << ", portal #" << the_data.portal; - } - - if ( the_data.glyph_code.isEmpty() == false ) - { - outs << "\nGlyph code: "; - outs.noquote() << the_data.glyph_code.toUpper(); - } - - if ( the_data.error_info.isEmpty() == false ) - { - outs << "\ninvalid segments: "; - outs.noquote() << the_data.showErrorInfo(); - } - } - - return (dbg); + QDebug outs = dbg.nospace(); + + outs << "[DEBUG][coordinateData]"; + + if ( (the_data.coordinates.isEmpty() == true + && the_data.glyph_code.isEmpty() == true) + || (the_data.coordinates == ":::" && the_data.glyph_code.isEmpty() == true) ) + { + outs << ": No coordinate data found.\n"; + } + else + { + if ( the_data.coordinates.size() > 0 + && the_data.coordinates != ":::" ) + { + outs << "\nCoordinates: "; + outs.noquote() << the_data.coordinates.toUpper(); + outs << ", portal #" << the_data.portal; + } + + if ( the_data.glyph_code.isEmpty() == false ) + { + outs << "\nGlyph code: "; + outs.noquote() << the_data.glyph_code.toUpper(); + } + + if ( the_data.error_info.isEmpty() == false ) + { + outs << "\ninvalid segments: "; + outs.noquote() << the_data.showErrorInfo(); + } + } + + return (dbg); } //------------------------------------------------------------------ std::ostream &operator << (std::ostream &outs, const coordinateData &the_data) { - outs << the_data.toString().toStdString(); + outs << the_data.toString().toStdString(); return (outs); } //------------------------------------------------------------------ std::ostream &operator << (std::ostream &outs, coordinateData &the_data) { - outs << the_data.toString().toStdString(); + outs << the_data.toString().toStdString(); return (outs); } //------------------------------------------------------------------ ////////////////////////// @@ -595,24 +609,24 @@ return (result); } //------------------------------------------------------------------ bool operator != (const coordinateData &a, const coordinateData &b) { - bool result = false; + bool result = false; - if ( !(a == b) ) - result = true; + if ( !(a == b) ) + result = true; return (result); } //------------------------------------------------------------------ bool operator != (coordinateData &a, coordinateData &b) { - bool result = false; + bool result = false; - if ( !(a == b) ) - result = true; + if ( !(a == b) ) + result = true; return (result); } //------------------------------------------------------------------ bool operator < (const coordinateData &a, const coordinateData &b) Index: src/CoordinateData.h ================================================================== --- src/CoordinateData.h +++ src/CoordinateData.h @@ -3,11 +3,13 @@ #define __COORDINATE_DATA_H__ //================================================================== #include //================================================================== /** \class CoordinateData + * * \brief Holds data about a coordinate and its glyph code. + * * \details A coordinate is comprised a 19-digit hexadecimal value, * colon-separated every 4 digits. * Its corresponding glyph code is a 12-digit hexadecimal value. * * Valid coordinates exist between: @@ -28,34 +30,40 @@ { public: ////////////////// // CONSTRUCTORS // ////////////////// - /** \details Default constructor. Initializes all variables to - * null/empty values. - */ - coordinateData(); + /** Default constructor. */ + explicit coordinateData(); /** \details Recommend constructor to initialize to a known * coordinate or glyph code. By default, a coordinate is * assumed to be provided as these are more common to - * encounter (requires less work to obtain). + * encounter (requires less effort to obtain). * * \param[in] _code A valid coordinate or glyph code. * \param[in] isCoordinate Defines the input type. + * * \warning No error-checking that isCoordinate correctly * corresponds to the type of input _code is. */ - coordinateData(const QString &_code, bool isCoordinate = true); + explicit coordinateData(const QString &_code, bool isCoordinate = true); + + /** Default destructor **/ + ~coordinateData(); // Copy Constructors /** \details Copy constructor for const CoordinateData object. * * \param[in] other An initialized CoordinateData object to * copy data from. */ coordinateData(const coordinateData &other); - /** \overload coordinateData(coordinateData &other) **/ + /** \overload coordinateData(coordinateData &other) + * + * \param[in] other An initialized CoordinateData object to + * copy data from. + */ coordinateData(coordinateData &other); // Assignment Operator /** \details Assignment operator for const CoordinateData * object. @@ -62,11 +70,15 @@ * * \param[in] source An initialized CoordinateData object to * copy data from. */ coordinateData &operator = (const coordinateData &source); - /** \overload operator=(coordinateData &source) */ + /** \overload operator=(coordinateData &source) + * + * \param[in] source An initialized CoordinateData object to + * copy data from. + */ coordinateData &operator = (coordinateData &source); //////////////////////////////// // ACCESSING MEMBER FUNCTIONS // //////////////////////////////// @@ -76,11 +88,15 @@ QString getCoordinate() const; /** \returns The coordinate. */ QString getCoordinates() const; /** \returns Error information about the code. */ QStringList getErrorInfo() const; - /** \returns Error information about the coordinate/glyph code. */ + /** Ideally this function should never be called unless + * there is something to display from error_info. + * + * \returns Error information about the coordinate/glyph code. + */ QString showErrorInfo() const; /** \returns The portal number. */ int getPortal() const; /** Prints the coordinates or glyph code in a human-readable * format. @@ -156,10 +172,11 @@ * 0123:0045:0678:009A, portal #2 * 000202002002 * * \param[in,out] readInputInto The stream to read data from. * \param[in,out] target The object to read data into. + * * \warning Avoid using as this is not fully tested, nor functional. */ friend QTextStream &operator >> (QTextStream &readInputInto, coordinateData &target); /** \details Outputs the contents of CoordinateData object in a * human-readable format. @@ -176,13 +193,13 @@ friend QTextStream &operator << (QTextStream &outs, coordinateData &the_data); /** \overload operator<<(QDebug, const coordinateData &) * * Allows output to QDebug stream. For example: * - * coordinateData b; - * b.setCoordinate ("0123:0045:0678:009A"); - * qDebug() << b; + * coordinateData b; + * b.setCoordinate ("0123:0045:0678:009a"); + * qDebug() << b; * * \param[in,out] dbg The QDebug stream to output data into. * \param[in] the_data The data to read data from. */ friend QDebug operator << (QDebug dbg, const coordinateData &the_data); @@ -191,27 +208,36 @@ * \param[in,out] dbg The QDebug stream to output data into. * \param[in] the_data The data to read data from. */ friend QDebug operator << (QDebug dbg, coordinateData &the_data); /** \overload operator<<(std::ostream &, const coordinateData &) + * * Allows output to a stream, for example std::cout. * * \param[in,out] outs The stream to output data into. * \param[in] the_data The data to read data from. */ friend std::ostream &operator << (std::ostream &outs, const coordinateData &the_data); + /** \overload operator<<(std::ostream &, coordinateData &) + * + * Allows output to a stream, for example std::cout. + * + * \param[in,out] outs The stream to output data into. + * \param[in] the_data The data to read data from. + */ + friend std::ostream &operator << (std::ostream &outs, coordinateData &the_data); private: /* PRIVATE FUNCTIONS */ /** \details Sets glyph code to empty value. */ - void initGlyphs(); + void createGlyphs(); /** \details Sets coordinate to empty value, and portal number * to default value of one (1). */ - void initCoordinates(); + void createCoordinates(); /* PRIVATE VARIABLES */ /** \var QString coordinates Index: src/CoordinateMain.cpp ================================================================== --- src/CoordinateMain.cpp +++ src/CoordinateMain.cpp @@ -10,27 +10,25 @@ QTextStream &outs, const bool verbosity) { coordinateData *window = new coordinateData(code, valid); window -> convertToGlyph(); -// qDebug() << *window; - if ( window -> getGlyphCode().isEmpty() == false ) outs << window -> getGlyphCode() << "\n"; else { if ( verbosity == true ) { - if ( window -> getErrorInfo().size() > 0 ) - outs << window -> showErrorInfo(); - else - { - if ( window -> getCoordinates().isEmpty() == false ) - outs << *window; - else - outs << "No coordinates provided."; - } + if ( window -> getErrorInfo().size() > 0 ) + outs << window -> showErrorInfo(); + else + { + if ( window -> getCoordinates().isEmpty() == false ) + outs << *window; + else + outs << "No coordinates provided."; + } } } } //------------------------------------------------------------------ void to_coords (const QString &code, const bool valid, @@ -37,12 +35,10 @@ QTextStream &outs, const bool verbosity) { coordinateData *guess = new coordinateData (code, valid); guess -> convertFromGlyph(); -// qDebug() << *guess; - if ( guess -> getCoordinate().isEmpty() == false ) { outs << guess -> getCoordinate() << ", portal #"; outs << guess -> getPortal() << "\n"; } @@ -52,16 +48,16 @@ { if ( guess -> getErrorInfo().size() > 0 ) outs << guess -> showErrorInfo(); else { - if ( guess -> getGlyphCode().isEmpty() == false ) - outs << *guess; - else - outs << "No glyph code provided."; - } - } + if ( guess -> getGlyphCode().isEmpty() == false ) + outs << *guess; + else + outs << "No glyph code provided."; + } + } } } //------------------------------------------------------------------ inline void setApplicationSettings() { @@ -122,19 +118,19 @@ if ( coord == true && glyph == false ) { // convert coordinates -> glyph for (int i = 0; i < args.size(); i++) { - to_glyphs (args.at(i), bool(true), outs, verb); + to_glyphs (args.at(i), true, outs, verb); } } else if ( glyph == true && coord == false ) { // convert glyph -> coordinates for (int i = 0; i < args.size(); i++) { - to_coords (args.at(i), bool(false), outs, verb); + to_coords (args.at(i), false, outs, verb); } } else { if ( args.size() == 0 ) @@ -148,54 +144,35 @@ for (int i = 0; i < args.size(); i++) { if ( args.at(i).size() == 12 ) { // Assume is glyph code - to_coords (args.at(i), bool(false), outs, verb); + to_coords (args.at(i), false, outs, verb); } else if ( args.at(i).size() == 19 ) { // Assume is coordinate - to_glyphs (args.at(i), bool(true), outs, verb); + to_glyphs (args.at(i), true, outs, verb); } - else { } + else { /* Assume invalid input */ } } } } - // Exit properly rather than keep waiting for input. + // Exit properly rather than waiting for input. app.quit(); } else { QApplication app (argc, argv); - setApplicationSettings(); - - // Set GUI style - QString gui_look = "Fusion", used; - - if ( argc >= 1 && argv[2] != QString() ) - { - const QString temp_string = argv[2]; - - if ( temp_string.size() < 15 ) - gui_look = QString(argv[2]); // Get GUI-style to use - } - - QApplication::setStyle(QStyleFactory::create(gui_look)); - used = QApplication::style() -> objectName(); - - if ( gui_look.toLower() != used.toLower() ) - { - qDebug() << gui_look << "cannot be used. Defaulting to" << - used; - qDebug() << "Available options for \'-style\':" << - QStyleFactory::keys().join(", "); - } + setApplicationSettings(); + + qDebug() << "Available options for \'-style\':" << + QStyleFactory::keys().join(", "); MainWindow main_screen; main_screen.show(); return app.exec (); } return (0); } Index: src/CoordinateMainWindow.cpp ================================================================== --- src/CoordinateMainWindow.cpp +++ src/CoordinateMainWindow.cpp @@ -6,49 +6,51 @@ //================================================================== /////////////////// // CLASS: Window // /////////////////// //================================================================== -Window::Window (QWidget *parent) : QWidget (parent) +Window::Window (QWidget *parent) + : QWidget (parent) { - initCoordinates(); - initGlyphs(); + createCoordinates(); + createGlyphs(); createLayout(); } //------------------------------------------------------------------ -Window::Window (const QString &_code, bool isCoordinate) +Window::Window (const QString &_code, bool isCoordinate, QWidget *parent) + : QWidget (parent) { - initCoordinates(); - initGlyphs(); + createCoordinates(); + createGlyphs(); if ( isCoordinate == false ) glyph_sequence -> setText (_code); else coordinates_input -> setText (_code); - createLayout(); + createLayout(); } //------------------------------------------------------------------ QString Window::getGlyphCode() { - return (glyph_sequence -> text()); + return (glyph_sequence -> text()); } //------------------------------------------------------------------ QString Window::getCoordinate() { - return (coordinates_input -> text()); + return (coordinates_input -> text()); } //------------------------------------------------------------------ QString Window::getCoordinates() { - return (getCoordinate()); + return (getCoordinate()); } //------------------------------------------------------------------ int Window::getPortal() { - return (portal_number -> value()); + return (portal_number -> value()); } //------------------------------------------------------------------ void Window::createLayout() { // Set minimum size of window @@ -202,15 +204,15 @@ // Set up QMessageBox::warning describing what is wrong with the // coordinate/glyph code QMessageBox *invalid_messages = new QMessageBox; QString text = QString(); - if ( the_errors.isEmpty() == true || QString(the_errors.join("")) == ":::" ) - text += QString (tr ("No code provided.")); - else + if ( the_errors.isEmpty() == true || QString(the_errors.join("")) == ":::" ) + text += QString (tr ("No code provided.")); + else { - text += QString(tr ("Problematic section: ")); + text += QString(tr ("Problematic section: ")); text += QString ("[" + the_errors.join ("] [") + "]"); text += "\n\n"; text += QString(tr ("Please adjust.")); } @@ -263,21 +265,21 @@ { setCoordinatePreset ("0467:0081:0D71:00AD", 1); GUI_convertToGlyph(); } //------------------------------------------------------------------ -void Window::initGlyphs() +void Window::createGlyphs() { // QLineEdit to store glyph code sequence glyph_sequence = new QLineEdit; glyph_sequence -> setMaxLength (12); glyph_sequence -> setPlaceholderText ("F00101001001"); glyph_sequence -> setCursorMoveStyle (Qt::VisualMoveStyle); glyph_sequence -> setClearButtonEnabled (true); } //------------------------------------------------------------------ -void Window::initCoordinates() +void Window::createCoordinates() { /* QLineEdit to store coordinate data Using inputMask rather than validator to allow for easier user edits of this input field. With validator, the user will @@ -306,84 +308,77 @@ clearGlyphCode(); } //------------------------------------------------------------------ void Window::clearCoordinates() { - coordinates_input -> clear(); - portal_number -> setValue (1); + coordinates_input -> clear(); + portal_number -> setValue (1); } //------------------------------------------------------------------ void Window::clearGlyphCode() { - glyph_sequence -> clear(); -} -//------------------------------------------------------------------ -void Window::clearMessages() -{ - //blackbox -> clearErrorInfo(); + glyph_sequence -> clear(); } //------------------------------------------------------------------ void Window::GUI_convertFromGlyph() { if ( glyph_sequence -> text().size() == 12 ) { - coordinateData *blackbox = new coordinateData; + coordinateData blackbox = coordinateData(); // Move user input into blackbox for conversion - blackbox -> setGlyphCode (glyph_sequence -> text()); + blackbox.setGlyphCode (glyph_sequence -> text()); // Perform conversion: glyph code -> coordinates - blackbox -> convertFromGlyph(); - - if ( blackbox -> getCoordinates().size() == 19 ) - { - // Move successful/valid conversion results to GUI - coordinates_input -> setText (blackbox -> getCoordinate()); - glyph_sequence -> setText (blackbox -> getGlyphCode()); - portal_number -> setValue (blackbox -> getPortal()); + blackbox.convertFromGlyph(); + + if ( blackbox.getCoordinates().size() == 19 ) + { + // Move successful conversion results to GUI + coordinates_input -> setText (blackbox.getCoordinate()); + glyph_sequence -> setText (blackbox.getGlyphCode()); + portal_number -> setValue (blackbox.getPortal()); emit validCoordinate(); } else { - qDebug() << "emitting haveErrors"; - qDebug() << *blackbox; - emit haveErrors (blackbox -> getErrorInfo()); + qDebug() << blackbox; + emit haveErrors (blackbox.getErrorInfo()); } } } //------------------------------------------------------------------ void Window::GUI_convertToGlyph() { if ( coordinates_input -> text().isEmpty() == false && coordinates_input -> text() != ":::" ) { - coordinateData *blackbox = new coordinateData; + coordinateData blackbox = coordinateData(); // Move user inputs to blackbox for conversion - blackbox -> setPortal (portal_number -> value()); - blackbox -> setCoordinate (coordinates_input -> text()); + blackbox.setPortal (portal_number -> value()); + blackbox.setCoordinate (coordinates_input -> text()); // Perform conversion: coordinates -> glyph code - blackbox -> convertToGlyph(); - - if ( blackbox -> getGlyphCode().size() == 12 ) - { - // Move successful/valid conversion results to GUI - glyph_sequence -> setText (blackbox -> getGlyphCode()); - coordinates_input -> setText (blackbox -> getCoordinate()); - portal_number -> setValue (blackbox -> getPortal()); + blackbox.convertToGlyph(); + + if ( blackbox.getGlyphCode().size() == 12 ) + { + // Move successful conversion results to GUI + glyph_sequence -> setText (blackbox.getGlyphCode()); + coordinates_input -> setText (blackbox.getCoordinate()); + portal_number -> setValue (blackbox.getPortal()); emit validGlyphCode(); } else { - qDebug() << "emitting haveErrors"; - qDebug() << *blackbox; - emit haveErrors (blackbox -> getErrorInfo()); + qDebug() << blackbox; + emit haveErrors (blackbox.getErrorInfo()); } } } //------------------------------------------------------------------ void Window::syncGlyphCode() { - emit glyphChange(); + emit glyphChange(); } //------------------------------------------------------------------ Index: src/CoordinateMainWindow.h ================================================================== --- src/CoordinateMainWindow.h +++ src/CoordinateMainWindow.h @@ -24,11 +24,11 @@ class Window : public QWidget { // Macro to allow for custom slots and signals Q_OBJECT - public: + public: ////////////////// // CONSTRUCTORS // ////////////////// /** Default constructor */ explicit Window(QWidget *parent = 0); @@ -35,85 +35,84 @@ /** \overload Window(const QString &, bool) * * \param[in] _code A valid coordinate or glyph code. * \param[in] isCoordinate Denotes _code as being a coordinate. */ - Window(const QString &_code, bool isCoordinate = true); + explicit Window(const QString &_code, bool isCoordinate = true, QWidget *parent = 0); //////////////////////////////// // ACCESSING MEMBER FUNCTIONS // //////////////////////////////// /** Initialize GUI objects/elements */ void createLayout(); - /** \returns The glyph code. */ - QString getGlyphCode(); - /** \returns The coordinates. */ - QString getCoordinate(); - /** Convenience function for getCoordinate. - * - * \returns The coordinates. - * - * \see getCoordinate - */ - QString getCoordinates(); - /** \returns The portal number. */ - int getPortal(); - - /** Sets the coordinate and portal value. Intended for location - * presets and as such has no error-checking of the provided - * inputs. - * - * \param[in] _code A valid coordinate. - * \param[in] _portal A valid portal number. - */ + /** \returns The glyph code. */ + QString getGlyphCode(); + /** \returns The coordinates. */ + QString getCoordinate(); + /** Convenience function for getCoordinate. + * + * \returns The coordinates. + * + * \see getCoordinate + */ + QString getCoordinates(); + /** \returns The portal number. */ + int getPortal(); + + /** Sets the coordinate and portal value. Intended for location + * presets and as such has no error-checking of the provided + * inputs. + * + * \param[in] _code A valid coordinate. + * \param[in] _portal A valid portal number. + */ void setCoordinatePreset(const QString &_code, const int _portal = 1); /** Sets the glyph code value. Intended for location presets * and as such has no error-checking of the provided _code. * * \param[in] _code A valid glyph code. */ void setGlyphCodePreset(const QString &_code); signals: - /** This signal is emitted when the coordinate or glyph code - * is invalid. - */ - void haveErrors (QStringList); + /** This signal is emitted when the coordinate or glyph code + * is invalid. + */ + void haveErrors(QStringList errorList); /** This signal is emitted when the glyph code has been * validated. */ - void validGlyphCode(); - /** This signal is emitted when the coordinate has been - * validated. - */ - void validCoordinate(); - /** This signal is emitted when there is a change to the - * glyphs. - */ - void glyphChange(); + void validGlyphCode(); + /** This signal is emitted when the coordinate has been + * validated. + */ + void validCoordinate(); + /** This signal is emitted when there is a change to the + * glyphs. + */ + void glyphChange(); public slots: - /** Calls the method to convert the current coordinates into - * a glyph code. - * - * \see CoordinateData::convertToGlyph - */ + /** Calls the method to convert the current coordinates into + * a glyph code. + * + * \see coordinateData::convertToGlyph + */ void GUI_convertToGlyph(); /** Calls the method to convert the current glyph code into * coordinates. * - * \see CoordinateData::convertFromGlyph + * \see coordinateData::convertFromGlyph */ void GUI_convertFromGlyph(); /** Emits the signal glyphChange. */ - void syncGlyphCode(); - //void about(); + void syncGlyphCode(); /** Show errors in a QMessageBox about the supplied code * preventing conversion. */ - void showMessages (QStringList); + void showMessages(QStringList the_errors); // Show coordinates/portal address for location preset /** Pre-fills coordinate data for the preset: HUB. */ void preset_hub(); /** Pre-fills coordinate data for the preset: Amino. */ @@ -132,34 +131,25 @@ void reset(); /** Clears coordinates value. */ void clearCoordinates(); /** Clears all glyph images. */ void clearGlyphCode(); - /** Clears error messages about coordinate data. - * - * This function is mostly useless as reset will perform this - * functionality as well. - * - * \deprecated To be removed by version 1.0. Consider using - * reset() instead. - */ - void clearMessages(); private: - /** Removes any existing glyphs. */ - void initGlyphs(); + /* + PRIVATE FUNCTIONS + */ + /** Removes any existing glyphs. */ + void createGlyphs(); /** Sets coordinates and portal number to default value: * empty, 1. */ - void initCoordinates(); - - /** \var coordinateData *blackbox - * - * \brief Holds temporary coordinate data. - */ - //coordinateData *blackbox; - + void createCoordinates(); + + /* + PRIVATE VARIABLES + */ // GUI-specific objects /** \var QLineEdit *coordinates_input * * \brief Holds the coordinates value. */ Index: src/HelperFunctions.cpp ================================================================== --- src/HelperFunctions.cpp +++ src/HelperFunctions.cpp @@ -91,11 +91,11 @@ } } else { result = false; - errors.append (__code); + errors.append (__code); } return (result); } //------------------------------------------------------------------ Index: src/HelperFunctions.h ================================================================== --- src/HelperFunctions.h +++ src/HelperFunctions.h @@ -4,11 +4,11 @@ * \brief Helper functions to assist in manipulating coordinate data. * * \details Provides convenience functions to facilitate converting * between coordinates and glyph codes. * - * \see CoordinateData + * \see coordinateData */ //------------------------------------------------------------------ #ifndef __HELPER_FUNCTIONS_H__ #define __HELPER_FUNCTIONS_H__ //------------------------------------------------------------------ Index: src/MainWindow.cpp ================================================================== --- src/MainWindow.cpp +++ src/MainWindow.cpp @@ -9,32 +9,35 @@ //------------------------------------------------------------------ ///////////////// // CONSTRUCTOR // ///////////////// //------------------------------------------------------------------ -MainWindow::MainWindow() +MainWindow::MainWindow (QWidget *parent) + : QMainWindow (parent), + conversion_screen (new Window(this)) { - setWindowTitle ("nmspd"); - - conversion_screen = new Window; setCentralWidget (conversion_screen); + setWindowTitle ("nmspd"); + // Create dock widget: Top portal_address = new Glyphs; QDockWidget *topWidget = new QDockWidget(tr ("Portal Address"), this); topWidget -> setAllowedAreas (Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); topWidget -> setFeatures (QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); topWidget -> setWidget (portal_address); addDockWidget (Qt::TopDockWidgetArea, topWidget); + // Create dock widget: Bottom glyph_selector = new PortalDialer; QDockWidget *bottomWidget = new QDockWidget (tr ("Glyph Entry"), this); bottomWidget -> setAllowedAreas (Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); bottomWidget -> setFeatures (QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); bottomWidget -> setWidget (glyph_selector); addDockWidget (Qt::BottomDockWidgetArea, bottomWidget); createActions(); + createStatusBar(); createMenus(); createToolBar(); } //------------------------------------------------------------------ ////////////////// @@ -86,10 +89,11 @@ } //------------------------------------------------------------------ /////////////////////// // PRIVATE FUNCTIONS // /////////////////////// +//------------------------------------------------------------------ void MainWindow::createToolBar() { // TODO: Find (or create) some icons to use for these toolbar // actions. As it stands, these are text-only toolbar buttons QToolBar *mainToolBar; @@ -96,22 +100,25 @@ mainToolBar = addToolBar (tr ("Control")); mainToolBar -> setAllowedAreas (Qt::AllToolBarAreas); // Toggle glyph entry window (PortalAddressPickerWindow -- Glyphs) QAction *showPortalAction = new QAction (tr ("&Glyph entry")); + showPortalAction -> setStatusTip (tr ("Show/Hide glyph entry window")); QObject::connect (showPortalAction, &QAction::triggered, this, &MainWindow::showPortal); mainToolBar -> addAction (showPortalAction); mainToolBar -> addSeparator (); - + // Toggle portal address window (PortalAddressWindow -- PortalDialer) QAction *showGlyphInput = new QAction (tr ("&Portal Address")); + showGlyphInput -> setStatusTip (tr ("Show/Hide portal address window")); QObject::connect (showGlyphInput, &QAction::triggered, this, &MainWindow::showGlyphs); mainToolBar -> addAction (showGlyphInput); mainToolBar -> addSeparator (); - + // Clear inputs of main window and portal address QAction *clearInputsAction = new QAction (tr ("Clear All")); + clearInputsAction -> setStatusTip (tr ("Reset coordinates, glyph code, and glyphs.")); QObject::connect (clearInputsAction, &QAction::triggered, this, &MainWindow::reset); mainToolBar -> addAction (clearInputsAction); mainToolBar -> addSeparator (); } //------------------------------------------------------------------ @@ -118,24 +125,25 @@ void MainWindow::createActions() { exit_action = new QAction (QIcon(QIcon::fromTheme ("application-exit")), tr ("E&xit")); exit_action -> setShortcuts (QKeySequence::Quit); exit_action -> setStatusTip (tr ("Exit the application")); - //connect (exit_action, &QAction::triggered, this, &QWidget::close); QObject::connect (exit_action, &QAction::triggered, this, &QApplication::quit); about_action = new QAction (tr ("&About")); about_action -> setStatusTip (tr ("Show the application's About box")); QObject::connect (about_action, &QAction::triggered, this, &MainWindow::about); about_qt_action = new QAction (tr ("About &Qt")); about_qt_action -> setStatusTip (tr ("Show the Qt library's About box")); QObject::connect (about_qt_action, &QAction::triggered, qApp, &QApplication::aboutQt); - + // TODO: Update glyph code from conversion_screen to // glyph_selector because right now it syncs one way: // glyph_selector --> conversion_screen. + // + // Edit: Let's not. QObject::connect (glyph_selector, &PortalDialer::codeChange, this, &MainWindow::updateGlyphsFromInputWindow); QObject::connect (conversion_screen, &Window::validCoordinate, this, &MainWindow::updatePortalAddressFromMainWindow); QObject::connect (conversion_screen, &Window::validGlyphCode, this, &MainWindow::updatePortalAddressFromMainWindow); QObject::connect (glyph_selector, &PortalDialer::codeReady, this, &MainWindow::conversion); QObject::connect (conversion_screen, &Window::glyphChange, this, &MainWindow::updateGlyphsToInputWindow); @@ -147,40 +155,45 @@ fileMenu -> addAction (exit_action); helpMenu = menuBar() -> addMenu (tr ("&Help")); helpMenu -> addAction (about_action); helpMenu -> addAction (about_qt_action); +} +//------------------------------------------------------------------ +void MainWindow::createStatusBar() +{ + statusBar() -> showMessage (tr ("Ready!"), 5000); } //------------------------------------------------------------------ /////////////////// // PRIVATE SLOTS // /////////////////// //------------------------------------------------------------------ void MainWindow::about() { - QMessageBox::about (this, tr ("About nmspd"), - tr ("

nmspd

v0.6.0


" - "Author: tion" - "
" - "
" - "

" - "The glyph symbols used in this program are slightly modified " - "from images on " - "" - "https://nomanssky.gamepedia.com. These images are " - "property of Hello Games. The use of " - "these images is for educational purposes only.


" - "This program is free software: you can redistribute it " - "and/or modify it under the terms of the GNU General " - "Public License as published by the Free Software " - "Foundation, either version 3 of the License, or (at your option) " - "any later version.

" - "This program is distributed in the hope that it will be useful, but " - "WITHOUT ANY WARRANTY; without even implied warranty of MERCHANTABILITY " - "or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License " - "for more details.

" - "You should have received a copy of the GNU General Public License along " - "with this program. If not, see <" - "" - "http//www.gnu.org/licenses/>.

")); + QMessageBox::about (this, tr ("About nmspd"), + tr ("

nmspd

v0.6.0


" + "Author: tion" + "
" + "
" + "

" + "The glyph symbols used in this program are slightly modified " + "from images on " + "" + "https://nomanssky.gamepedia.com. These images are " + "property of Hello Games. The use of " + "these images is for educational purposes only.


" + "This program is free software: you can redistribute it " + "and/or modify it under the terms of the GNU General " + "Public License as published by the Free Software " + "Foundation, either version 3 of the License, or (at your option) " + "any later version.

" + "This program is distributed in the hope that it will be useful, but " + "WITHOUT ANY WARRANTY; without even implied warranty of MERCHANTABILITY " + "or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License " + "for more details.

" + "You should have received a copy of the GNU General Public License along " + "with this program. If not, see <" + "" + "http//www.gnu.org/licenses/>.

")); } //------------------------------------------------------------------ Index: src/MainWindow.h ================================================================== --- src/MainWindow.h +++ src/MainWindow.h @@ -1,28 +1,22 @@ //================================================================== #ifndef __NMS_CONVERT_MAIN_WINDOW_H__ #define __NMS_CONVERT_MAIN_WINDOW_H__ //================================================================== -#include -#include -#include - #include "CoordinateMainWindow.h" #include "PortalAddressWindow.h" #include "PortalAddressPickerWindow.h" //================================================================== -//class ToolBar; -//QT_FORWARD_DECLARE_CLASS (QMenu) /** \class MainWindow * * \brief The main window to handle coordinate/glyph code * conversion. * * To create a MainWindow: * - * // Create a bare object - * MainWindow example; + * MainWindow example; + * example.show(); * */ class MainWindow : public QMainWindow { Q_OBJECT @@ -30,40 +24,42 @@ public: ///////////////// // CONSTRUCTOR // ///////////////// /** Default constructor. */ - MainWindow(); + explicit MainWindow(QWidget *parent = 0); signals: public slots: //void action_triggered (QAction *); /** Show input portal address window. */ void showPortal(); /** Show resulting portal address window. */ void showGlyphs(); - /** Updates changes to glyphs into glyph code input field. */ + /** Updates changes to glyphs into glyph code input field. */ void updateGlyphsToInputWindow(); /** Updates changes from input field to glyphs. */ - void updateGlyphsFromInputWindow(); - /** Updates changes from input fields to portal address. */ - void updatePortalAddressFromMainWindow(); - /** Calls the methods to convert the coordinates or glyph code - * into a portal address. - */ - void conversion(); - /** Clears all input fields, glyphs, and portal address. */ - void reset(); + void updateGlyphsFromInputWindow(); + /** Updates changes from input fields to portal address. */ + void updatePortalAddressFromMainWindow(); + /** Calls the methods to convert the coordinates or glyph code + * into a portal address. + */ + void conversion(); + /** Clears all input fields, glyphs, and portal address. */ + void reset(); private: - /** Initializes and sets the menu items. */ + /** Initializes and sets the menu items. */ void createMenus(); /** Initializes actions for menu items and private variables. */ void createActions(); /** Initializes and sets the toolbar items. */ - void createToolBar(); + void createToolBar(); + /** Initializes the status bar. */ + void createStatusBar(); // MenuBar items /** \var QMenu *fileMenu * * \brief Menu item for 'File'. @@ -95,29 +91,29 @@ * * \brief Action to view information about Qt. */ QAction *about_qt_action; - /** \var Window *conversion_screen - * - * \brief Central widget showing the input fields for - * coordinates and glyph code. - * - * \see Window - */ - Window *conversion_screen; - /** \var Glyphs *portal_address - * - * \brief Top dock widget showing the resulting portal - * address. - */ - Glyphs *portal_address; - /** \var PortalDialer *glyph_selector - * - * \brief Bottom dock widget showing the glyph selection - * window. - */ + /** \var Window *conversion_screen + * + * \brief Central widget showing the input fields for + * coordinates and glyph code. + * + * \see Window + */ + Window *conversion_screen; + /** \var Glyphs *portal_address + * + * \brief Top dock widget showing the resulting portal + * address. + */ + Glyphs *portal_address; + /** \var PortalDialer *glyph_selector + * + * \brief Bottom dock widget showing the glyph selection + * window. + */ PortalDialer *glyph_selector; private slots: // Respond to user activating the menu entries. /** Show a QMessageBox with information about this program. */ Index: src/PortalAddressPickerWindow.cpp ================================================================== --- src/PortalAddressPickerWindow.cpp +++ src/PortalAddressPickerWindow.cpp @@ -4,47 +4,47 @@ //================================================================== ///////////////////////// // CLASS: PortalDialer // ///////////////////////// //------------------------------------------------------------------ -PortalDialer::PortalDialer (QWidget *parent) : QWidget (parent) +PortalDialer::PortalDialer (QWidget *parent) + : QWidget (parent) { - initGlyphs(); - initLayout(); + createGlyphs(); + createActions(); + createLayout(); } //------------------------------------------------------------------ -PortalDialer::PortalDialer (const QString &_code) +PortalDialer::PortalDialer (const QString &_code, QWidget *parent) + : QWidget (parent) { - initGlyphs(); + createGlyphs(); setGlyphs(_code); - initLayout(); + createActions(); + createLayout(); } //------------------------------------------------------------------ -void PortalDialer::initGlyphs() +void PortalDialer::createGlyphs() { + glyph_code = new QLineEdit; + glyph_code -> setMaxLength (12); + glyph_code -> setReadOnly (true); + code = new QStack; code -> clear(); for (int i = 0; i < 16; i++) { glyph_input[i] = new QPushButton; + glyph_input[i] -> setDisabled (false); glyph_input[i] -> setIconSize (QSize(40, 40)); + glyph_input[i] -> setMaximumSize (QSize (60,60)); glyph_input[i] -> setAutoFillBackground (false); glyph_input[i] -> setCheckable (false); - glyph_input[i] -> setFlat (false); + glyph_input[i] -> setFlat (true); glyph_input[i] -> setIcon (QIcon (QString (":" + QString( convert_integer_to_hex(i)).toUpper() + QString(".jpg")))); - /* - if ( i < 12 ) { - glyph_select[i] = new QPushButton; - glyph_select[i] -> setFlat (false); - glyph_select[i] -> setCheckable (false); - glyph_select[i] -> setAutoFillBackground (true); - glyph_select[i] -> setIconSize (QSize(60, 60)); - glyph_select[i] -> setIcon (QIcon (QString (":empty.png"))); - } - */ } } //------------------------------------------------------------------ void PortalDialer::setGlyphs (const QString &_code) { @@ -54,12 +54,11 @@ if ( code -> isEmpty() == false && (_code.toLower() != glyph_code -> text().toLower()) ) { reset(); - QStack temp; - temp.clear(); + QStack temp = QStack(); const QRegularExpression validHex ("[0-9A-F]"); QRegularExpressionMatch isValidHex; for (int i = 0; i < 12; i++) { @@ -72,18 +71,14 @@ { isValidHex = validHex.match (_code.at(i).toUpper()); if ( isValidHex.hasMatch() == true ) { - //code -> push(_code.at(i).toUpper()); - temp.push(_code.at(i).toUpper()); - //emit codeChange(); - fileName = ":" + QString(_code.at(i)).toUpper() + ".jpg"; + temp.push (_code.at (i).toUpper()); + fileName = ":" + QString(_code.at (i)).toUpper() + ".jpg"; } } - - //glyph_select[i] -> setIcon (QIcon (QString (fileName))); } glyph_code -> setText (getCode()); code -> swap (temp); emit codeChange(); @@ -100,33 +95,23 @@ { QString result = QString(); for (int i = 0; i < code -> size(); i++) { - result += QString(code -> at(i)); + result += QString(code -> at (i)); } return (result); } //------------------------------------------------------------------ void PortalDialer::getGlyph (const int index) { - if ( code -> size() < 12 ) - { - int i = (code -> size()); - QChar result = convert_integer_to_hex(index).at(0); - - if ( i < 0 ) - i = 0; - - if ( i < 12 ) - { - //glyph_select[i] -> setIcon (QIcon (QString (":" + QString(result) + ".jpg"))); - code -> push(result); - glyph_code -> setText (getCode()); - emit codeChange(); - } + if ( code -> size() >= 0 && code -> size() < 12 ) + { + code -> push (convert_integer_to_hex(index).at (0)); + glyph_code -> setText (getCode()); + emit codeChange(); } // Update status of code after (any) change if ( code -> size() == 12 ) emit codeReady(); @@ -152,24 +137,34 @@ void PortalDialer::clearOne() { if ( code -> isEmpty() == false ) { code -> pop(); - //glyph_select[code -> size()] -> setIcon (QIcon (QString (":empty.png"))); glyph_code -> setText (getCode()); emit codeIncomplete(); } emit codeChange(); } //------------------------------------------------------------------ -void PortalDialer::initLayout() +void PortalDialer::createActions() { - glyph_code = new QLineEdit; - glyph_code -> setMaxLength (12); - glyph_code -> setReadOnly (true); + // Glyph buttons + for (int i = 0; i < 16; i++) + { + QObject::connect (glyph_input[i], &QPushButton::clicked, this, [=] { getGlyph (i); }); + } + + // Block further input once full code has been entered + QObject::connect (this, &PortalDialer::codeReady, this, &PortalDialer::disableGlyphInput); + // Re-enable input for less than full code + QObject::connect (this, &PortalDialer::codeIncomplete, this, &PortalDialer::enableGlyphInput); +} +//------------------------------------------------------------------ +void PortalDialer::createLayout() +{ QPushButton *back_button = new QPushButton; back_button -> setText (tr ("Delete")); back_button -> setToolTip ( tr ("Backspace/Delete one digit to the left")); back_button -> setCheckable (false); @@ -180,16 +175,16 @@ reset_button -> setCheckable (false); /* Create grid layout. - control_group: - +--------+-------+ - | delete | clear | - +--------+-------+ - | glyph_code | - +----------------+ + control_group: + +--------+-------+ + | delete | clear | + +--------+-------+ + | glyph_code | + +----------------+ */ QGroupBox *control_group = new QGroupBox; QGridLayout *buttons = new QGridLayout; buttons -> addWidget (back_button, 0, 0, 1, 1); buttons -> addWidget (reset_button, 0, 1, 1, 1); @@ -236,13 +231,27 @@ Handle pushing the buttons */ // Delete glyph(s) previously selected QObject::connect (back_button, &QPushButton::clicked, this, &PortalDialer::clearOne); QObject::connect (reset_button, &QPushButton::clicked,this, &PortalDialer::reset); - - // Glyph buttons +} +//------------------------------------------------------------------ +/////////////////// +// PRIVATE SLOTS // +/////////////////// +//------------------------------------------------------------------ +void PortalDialer::disableGlyphInput() +{ + for (int i = 0; i < 16; i++) + { + glyph_input[i] -> setDisabled (true); + } +} +//------------------------------------------------------------------ +void PortalDialer::enableGlyphInput() +{ for (int i = 0; i < 16; i++) { - QObject::connect (glyph_input[i], &QPushButton::clicked, this, [=] { getGlyph (i); }); + glyph_input[i] -> setDisabled (false); } } //------------------------------------------------------------------ Index: src/PortalAddressPickerWindow.h ================================================================== --- src/PortalAddressPickerWindow.h +++ src/PortalAddressPickerWindow.h @@ -12,89 +12,108 @@ * \details Displays a list of possible glyphs and accepts any * sequence of glyphs the user may wish to input. * * To create a PortalDialer: * - * // Create an empty object - * PortalDialer example; + * // Create an empty object + * PortalDialer example; * - * // Show a specific glyph code sequence - * example.setGlyphs ("00234567890AB"); - * example.show(); + * // Show a specific glyph code sequence + * example.setGlyphs ("00234567890AB"); + * example.show(); * */ class PortalDialer : public QWidget { Q_OBJECT - public: + public: ////////////////// // CONSTRUCTORS // ////////////////// /** Default constructor */ explicit PortalDialer(QWidget *parent = 0); /** \overload PortalDialer(const QString &) * * \param[in] _code A valid glyph code to set as. */ - PortalDialer(const QString &_code); + explicit PortalDialer(const QString &_code, QWidget *parent = 0); - /** - * \details Sets the glyph code along with its corresponding glyphs. - * - * \param[in] _code A valid glyph code. - */ + /** + * \details Sets the glyph code along with its corresponding glyphs. + * + * \param[in] _code A valid glyph code. + */ void setGlyphs(const QString &_code); /** \returns The glyph code. */ QString getCode(); - signals: - /** This signal is emitted when there is a change to the glyph code. */ - void codeChange(); - /** This signal is emitted when the glyph code has not been filled to - * twelve (12) hex characters. Indicates the glyph code is between 0 - * and 11 characters. - */ - void codeIncomplete(); - /** This signal is emitted when the glyph code has been filled to twelve - * (12) hex characters. Indicates the glyph code is ready to be - * validated. - */ - void codeReady(); - - public slots: - /** Removes the most recent/last glyph selected. */ - void clearOne(); - /** Clears the glyphs and glyph code. */ + signals: + /** This signal is emitted when there is a change to the glyph code. */ + void codeChange(); + /** This signal is emitted when the glyph code has not been filled to + * twelve (12) hex characters. Indicates the glyph code is between 0 + * and 11 characters. + */ + void codeIncomplete(); + /** This signal is emitted when the glyph code has been filled to twelve + * (12) hex characters. Indicates the glyph code is ready to be + * validated. + */ + void codeReady(); + + public slots: + /** Removes the most recent/last glyph selected. */ + void clearOne(); + /** Clears the glyphs and glyph code. */ void reset(); /** Selects the glyph image corresponding to the value of index. * * \param[in] index An integer between 0 - 15. */ - void getGlyph(const int index); + void getGlyph(const int index); - private: - /** Initializes glyph_input to empty QPushButtons. */ - void initGlyphs(); + private: + /* + PRIVATE FUNCTIONS + */ + /** Initializes glyph_input to empty QPushButtons. */ + void createGlyphs(); /** Initializes the layout. */ - void initLayout(); + void createLayout(); + /** Initializes actions for the private variables. */ + void createActions(); + /* + PRIVATE VARIABLES + */ /** \var QPushButton *glyph_input[16] * * Holds the glyph image for each possible glyph. */ - QPushButton *glyph_input[16]; - /** \var QStack *code - * - * Stores the selected glyph code. - */ - QStack *code; - /** \var QLineEdit *glyph_code - * - * Displays the current glyph code. - */ - QLineEdit *glyph_code; - //QPushButton *glyph_select[12]; + QPushButton *glyph_input[16]; + /** \var QStack *code + * + * Stores the selected glyph code. + */ + QStack *code; + /** \var QLineEdit *glyph_code + * + * Displays the current glyph code. + */ + QLineEdit *glyph_code; + + private slots: + /** Disables all glyph input. Useful when 12 codes have been + * entered. + * + * Should only be called when codeReady is emitted. + */ + void disableGlyphInput(); + /** Enables all glyph input. This is the default state of the + * object. + */ + void enableGlyphInput(); }; //================================================================== #endif // __NMS_PORTAL_DIAL_H__ //================================================================== Index: src/PortalAddressWindow.cpp ================================================================== --- src/PortalAddressWindow.cpp +++ src/PortalAddressWindow.cpp @@ -1,28 +1,30 @@ -//================================================================== +//------------------------------------------------------------------ #include "PortalAddressWindow.h" #include "HelperFunctions.h" -//================================================================== +//------------------------------------------------------------------ /////////////////// // CLASS: Glyphs // /////////////////// -//================================================================== -Glyphs::Glyphs (QWidget *parent) : QWidget (parent) +//------------------------------------------------------------------ +Glyphs::Glyphs (QWidget *parent) + : QWidget (parent) { - initGlyphs(); + createGlyphs(); setGlyphs (QString()); createLayout(); } //------------------------------------------------------------------ -Glyphs::Glyphs (const QString &_code) +Glyphs::Glyphs (const QString &_code, QWidget *parent) + : QWidget (parent) { - initGlyphs(); + createGlyphs(); setGlyphs (_code); createLayout(); } //------------------------------------------------------------------ -void Glyphs::initGlyphs() +void Glyphs::createGlyphs() { for (int i = 0; i < 12; i++) glyph[i] = new QPushButton; } //------------------------------------------------------------------ @@ -33,37 +35,41 @@ // Do not change glyph code if provided code is the same as // what we already have; just redraw it. Also must be a valid // glyph code. if ( glyph_code.toLower() != _code.toLower() && (is_valid_glyph_code (_code, ignoreThis) == true) ) + { glyph_code = _code; + } for (int i = 0; i < 12; i++) { // Using aliases from qrc if ( _code.isEmpty() == false ) + { glyph[i] -> setIcon (QIcon (QString(":" + QString(glyph_code.at( i).toUpper()) + ".jpg"))); + } else glyph[i] -> setIcon (QIcon (QString(":empty.png"))); glyph[i] -> setIconSize (QSize(40, 40)); // (60,60) is nice, too glyph[i] -> setAutoFillBackground (true); glyph[i] -> setText (QString()); glyph[i] -> setCheckable (false); - glyph[i] -> setFlat (false); + glyph[i] -> setFlat (true); } } //------------------------------------------------------------------ void Glyphs::showGlyphs() { - setGlyphs (glyph_code); + setGlyphs (glyph_code); } //------------------------------------------------------------------ void Glyphs::showGlyphs (const QString &_code) { - setGlyphs (_code); + setGlyphs (_code); } //------------------------------------------------------------------ void Glyphs::reset() { glyph_code.clear(); @@ -71,21 +77,10 @@ glyph[i] -> setIcon (QIcon (":empty.png")); } //------------------------------------------------------------------ void Glyphs::createLayout() { - /* - QPushButton *go_back = new QPushButton; - go_back -> setText (tr ("Hide")); - go_back -> setToolTip (tr ("Hide portal address window")); - go_back -> setCheckable (false); - - QPushButton *exit = new QPushButton; - exit -> setText (tr ("Quit")); - exit -> setToolTip (tr ("Exit the application")); - exit -> setCheckable (false); - */ /* Create horizontal layout. the_glyphs: +--------+--------+-----+---------+ @@ -98,26 +93,10 @@ for (int i = 0; i < 12; i++) sequence -> addWidget (glyph[i]); the_glyphs -> setLayout (sequence); - /* - Create vertical layout. - - the_buttons: - +---------+ - | go_back | - +---------+ - | exit | - +---------+ - */ - //QGroupBox *the_buttons = new QGroupBox; - //QVBoxLayout *_buttons = new QVBoxLayout; - //_buttons -> addWidget (go_back); - //_buttons -> addWidget (exit); - //the_buttons -> setLayout (_buttons); - /* Create grid layout for the program. _layout: +----------------------------+ @@ -124,17 +103,8 @@ | the_buttons | the_glyphs | +---------+------------------+ */ QGridLayout *_layout = new QGridLayout; _layout -> addWidget (the_glyphs, 0, 1, 1, 1); - //_layout -> addWidget (the_buttons, 0, 0, 2, 1); setLayout (_layout); - - // Handle button signals (events) - // Note: Using hide() rather than close() seems to keep memory - // usage more consistent while application is open. - //QObject::connect (go_back, SIGNAL (clicked(bool)), - // this, SLOT (hide())); - //QObject::connect (exit, SIGNAL (clicked(bool)), - // QApplication::instance(), SLOT (quit())); -} -//================================================================== +} +//------------------------------------------------------------------ Index: src/PortalAddressWindow.h ================================================================== --- src/PortalAddressWindow.h +++ src/PortalAddressWindow.h @@ -10,18 +10,18 @@ * * \details Displays the glyphs in a given a glyph code sequence. * * To create a Glyphs: * - * // Create empty glyph sequence - * Glyphs example; - * - * // Show sequence: 200d01345678 - * example.showGlyphs ("200d01345678"); - * example.show(); - * - * \see CoordinateData::glyph_code + * // Create empty glyph sequence + * Glyphs example; + * + * // Show sequence: 200d01345678 + * example.showGlyphs ("200d01345678"); + * example.show(); + * + * \see coordinateData::glyph_code */ class Glyphs : public QWidget { // Macro to allow for custom slots and signals Q_OBJECT @@ -38,14 +38,11 @@ * * \param[in] _code A valid glyph code. * * \see CoordinateData::glyph_code */ - Glyphs(const QString &_code); - - /** Initializes the GUI elements */ - void createLayout(); + explicit Glyphs(const QString &_code, QWidget *parent = 0); //////////////////////////////// // ACCESSING MEMBER FUNCTIONS // //////////////////////////////// /** Sets the glyph code sequence to be displayed. @@ -71,27 +68,35 @@ * \param[in] _code A valid glyph code. */ void showGlyphs(const QString &_code); private: - /** \var QString glyph_code - * - * The glyph code sequence to be displayed. - * - * \see CoordinateData::glyph_code - */ + /* + PRIVATE VARIABLES + */ + /** \var QString glyph_code + * + * The glyph code sequence to be displayed. + * + * \see CoordinateData::glyph_code + */ QString glyph_code; /** \var QPushButton *glyph[12] * * The actual glyphs corresponding to the glyph code. */ QPushButton *glyph[12]; - /** Initializes private variables: - * - * glyph_code of size zero, and empty QPushButtons for the glyphs. - */ - void initGlyphs(); + /* + PRIVATE FUNCTIONS + */ + /** Initializes private variables: + * + * glyph_code of size zero, and empty QPushButtons for the glyphs. + */ + void createGlyphs(); + /** Initializes the GUI elements */ + void createLayout(); }; //================================================================== #endif // __NMS_GLYPHS_H__ //==================================================================