Пример #1
0
static void TXT_CalcTableSize(TXT_UNCAST_ARG(table))
{
    TXT_CAST_ARG(txt_table_t, table);
    unsigned int *column_widths;
    unsigned int *row_heights;
    int x, y;
    int rows;

    rows = TableRows(table);

    row_heights = malloc(sizeof(int) * rows);
    column_widths = malloc(sizeof(int) * table->columns);

    CalcRowColSizes(table, row_heights, column_widths);

    table->widget.w = 0;

    for (x=0; x<table->columns; ++x)
    {
        table->widget.w += column_widths[x];
    }

    table->widget.h = 0;

    for (y=0; y<rows; ++y)
    {
        table->widget.h += row_heights[y];
    }

    free(row_heights);
    free(column_widths);
}
Пример #2
0
Data::Data(QObject *parent) :
    QObject(parent)
{
    //qDebug() << "data::constructor";
    this->m_manager = new QNetworkAccessManager(this);
    this->m_reply = 0;
    this->m_reply2 = 0;
    this->m_reply3 = 0;
    this->m_subjectsReply = 0;
    this->m_replyTeaching = 0;
    this->m_lessonsReply = 0;
    this->m_modifyReply = 0;
    this->m_insertReply = 0;

    Data::m_instance = this;

    this->m_weekDays = QList<WeekDay>();
    this->m_periods = QList<Period>();
    this->m_classes = QList<ClassData>();
    this->m_subjects = QList<SubjectData>();
    this->m_teachers = QList<TeacherData>();
    this->m_rooms = QList<RoomData>();
    this->m_teachings = QList<TeachingData>();
    this->m_lessons = QList<LessonData>();
    this->m_numStuds = 0;
    this->m_holes = QList<HoleData>();
    this->m_tableRows = TableRows();
}
Пример #3
0
static void TXT_TableLayout(TXT_UNCAST_ARG(table))
{
    TXT_CAST_ARG(txt_table_t, table);
    unsigned int *column_widths;
    unsigned int *row_heights;
    int draw_x, draw_y;
    int x, y;
    int i;
    int rows;

    // Work out the column widths and row heights

    rows = TableRows(table);

    column_widths = malloc(sizeof(int) * table->columns);
    row_heights = malloc(sizeof(int) * rows);

    CalcRowColSizes(table, row_heights, column_widths);

    // If this table only has one column, expand column size to fit
    // the display width.  Ensures that separators reach the window edges 
    // when drawing windows.

    if (table->columns == 1)
    {
        column_widths[0] = table->widget.w;
    }

    // Draw all cells
    
    draw_y = table->widget.y;
    
    for (y=0; y<rows; ++y)
    {
        draw_x = table->widget.x;

        for (x=0; x<table->columns; ++x)
        {
            i = y * table->columns + x;

            if (i >= table->num_widgets)
                break;

            if (table->widgets[i] != NULL)
            {
                LayoutCell(table, x, y, column_widths[x], 
                           draw_x, draw_y);
            }

            draw_x += column_widths[x];
        }

        draw_y += row_heights[y];
    }

    free(row_heights);
    free(column_widths);
}
Пример #4
0
// Most widgets occupy just one cell of a table, but if the special
// overflow constants are used, they can occupy multiple cells.
// This function figures out for a widget in a given cell, which
// cells it should actually occupy (always a rectangle).
static void CellOverflowedSize(txt_table_t *table, int x, int y,
                               int *w, int *h)
{
    txt_widget_t *widget;
    int x1, y1;

    if (!IsActualWidget(table->widgets[y * table->columns + x]))
    {
        *w = 0; *h = 0;
        return;
    }

    *w = table->columns - x;
    *h = 0;
    for (y1 = y; y1 < TableRows(table); ++y1)
    {
        // Every overflow cell must point to either (x, y) or another
        // overflow cell. This means the first in every row must be
        // txt_table_overflow_down.
        widget = table->widgets[y1 * table->columns + x];
        if (y1 != y && widget != &txt_table_overflow_down)
        {
            break;
        }

        for (x1 = x + 1; x1 < x + *w; ++x1)
        {
            if (y1 * table->columns + x1 >= table->num_widgets)
            {
                break;
            }

            // Can be either type of overflow, except on the first row.
            // Otherwise we impose a limit on the width.
            widget = table->widgets[y1 * table->columns + x1];
            if (widget != &txt_table_overflow_right
             && (widget != &txt_table_overflow_down || y1 == y))
            {
                *w = x1 - x;
                break;
            }
        }

        ++*h;
    }
}
Пример #5
0
static void CheckValidSelection(txt_table_t *table)
{
    int rows;
    int new_x, new_y;

    rows = TableRows(table);

    for (new_y = table->selected_y; new_y < rows; ++new_y)
    {
        new_x = FindSelectableColumn(table, new_y, table->selected_x);

        if (new_x >= 0)
        {
            // Found a selectable column.

            ChangeSelection(table, new_x, new_y);

            break;
        }
    }
}
Пример #6
0
static void CalcRowColSizes(txt_table_t *table, 
                            unsigned int *row_heights, 
                            unsigned int *col_widths)
{
    int x, y;
    int rows;
    txt_widget_t *widget;

    rows = TableRows(table);

    memset(col_widths, 0, sizeof(int) * table->columns);

    for (y=0; y<rows; ++y)
    {
        row_heights[y] = 0;

        for (x=0; x<table->columns; ++x)
        {
            if (y * table->columns + x >= table->num_widgets)
                break;

            widget = table->widgets[y * table->columns + x];

            // NULL represents an empty spacer

            if (widget != NULL)
            {
                TXT_CalcWidgetSize(widget);
                if (widget->h > row_heights[y])
                    row_heights[y] = widget->h;
                if (widget->w > col_widths[x])
                    col_widths[x] = widget->w;
            }
        }
    }
}
Пример #7
0
int TXT_PageTable(TXT_UNCAST_ARG(table), int pagex, int pagey)
{
    TXT_CAST_ARG(txt_table_t, table);
    unsigned int *column_widths;
    unsigned int *row_heights;
    int rows;
    int changed = 0;

    rows = TableRows(table);

    row_heights = malloc(sizeof(int) * rows);
    column_widths = malloc(sizeof(int) * table->columns);

    CalcRowColSizes(table, row_heights, column_widths);

    if (pagex)
    {
        // @todo Jump selection to the left or right as needed
    }

    if (pagey)
    {
        int new_x, new_y;
        int distance = 0;
        int dir;

        // What direction are we moving?

        if (pagey > 0)
        {
            dir = 1;
        }
        else
        {
            dir = -1;
        }

        // Move the cursor until the desired distance is reached.

        new_y = table->selected_y;

        while (new_y >= 0 && new_y < rows)
        {
            // We are about to travel a distance equal to the height of the row
            // we are about to leave.

            distance += row_heights[new_y];

            // *Now* increment the loop.

            new_y += dir;

            new_x = FindSelectableColumn(table, new_y, table->selected_x);

            if (new_x >= 0)
            {
                // Found a selectable widget in this column!
                // Select it anyway in case we don't find something better.

                table->selected_x = new_x;
                table->selected_y = new_y;
                changed = 1;

                // ...but is it far enough away?

                if (distance >= abs(pagey))
                {
                    break;
                }
            }
        }
    }

    free(row_heights);
    free(column_widths);

    return changed;
}
Пример #8
0
static int TXT_TableKeyPress(TXT_UNCAST_ARG(table), int key)
{
    TXT_CAST_ARG(txt_table_t, table);
    int selected;
    int rows;

    rows = TableRows(table);

    // Send to the currently selected widget first

    selected = table->selected_y * table->columns + table->selected_x;

    if (selected >= 0 && selected < table->num_widgets)
    {
        if (table->widgets[selected] != NULL
         && table->widgets[selected]->selectable
         && TXT_WidgetKeyPress(table->widgets[selected], key))
        {
            return 1;
        }
    }

    if (key == KEY_DOWNARROW)
    {
        int new_x, new_y;

        // Move cursor down to the next selectable widget

        for (new_y = table->selected_y + 1; new_y < rows; ++new_y)
        {
            new_x = FindSelectableColumn(table, new_y, table->selected_x);
                            
            if (new_x >= 0)
            {
                // Found a selectable widget in this column!

                table->selected_x = new_x;
                table->selected_y = new_y;

                return 1;
            }
        } 
    }

    if (key == KEY_UPARROW)
    {
        int new_x, new_y;

        // Move cursor up to the next selectable widget

        for (new_y = table->selected_y - 1; new_y >= 0; --new_y)
        {
            new_x = FindSelectableColumn(table, new_y, table->selected_x);
                            
            if (new_x >= 0)
            {
                // Found a selectable widget in this column!

                table->selected_x = new_x;
                table->selected_y = new_y;

                return 1;
            }
        } 
    }

    if (key == KEY_LEFTARROW)
    {
        int new_x;

        // Move cursor left

        for (new_x = table->selected_x - 1; new_x >= 0; --new_x)
        {
            if (SelectableWidget(table, new_x, table->selected_y))
            {
                // Found a selectable widget!

                table->selected_x = new_x;

                return 1;
            }
        }
    }

    if (key == KEY_RIGHTARROW)
    {
        int new_x;

        // Move cursor left

        for (new_x = table->selected_x + 1; new_x < table->columns; ++new_x)
        {
            if (SelectableWidget(table, new_x, table->selected_y))
            {
                // Found a selectable widget!

                table->selected_x = new_x;

                return 1;
            }
        }
    }

    return 0;
}
Пример #9
0
static int TXT_TableKeyPress(TXT_UNCAST_ARG(table), int key)
{
    TXT_CAST_ARG(txt_table_t, table);
    int selected;
    int rows;

    rows = TableRows(table);

    // Send to the currently selected widget first

    selected = table->selected_y * table->columns + table->selected_x;

    if (selected >= 0 && selected < table->num_widgets)
    {
        if (IsActualWidget(table->widgets[selected])
         && TXT_SelectableWidget(table->widgets[selected])
         && TXT_WidgetKeyPress(table->widgets[selected], key))
        {
            return 1;
        }
    }

    if (key == KEY_TAB)
    {
        int dir;
        int i;

        dir = TXT_GetModifierState(TXT_MOD_SHIFT) ? -1 : 1;

        // Cycle through all widgets until we find one that can be selected.
        for (i = table->selected_y * table->columns + table->selected_x + dir;
             i >= 0 && i < table->num_widgets;
             i += dir)
        {
            if (IsActualWidget(table->widgets[i])
             && TXT_SelectableWidget(table->widgets[i]))
            {
                ChangeSelection(table, i % table->columns, i / table->columns);
                return 1;
            }
        }

        return 0;
    }

    if (key == KEY_DOWNARROW)
    {
        int new_x, new_y;

        // Move cursor down to the next selectable widget

        for (new_y = table->selected_y + 1; new_y < rows; ++new_y)
        {
            new_x = FindSelectableColumn(table, new_y, table->selected_x);

            if (new_x >= 0)
            {
                // Found a selectable widget in this column!

                ChangeSelection(table, new_x, new_y);

                return 1;
            }
        }
    }

    if (key == KEY_UPARROW)
    {
        int new_x, new_y;

        // Move cursor up to the next selectable widget

        for (new_y = table->selected_y - 1; new_y >= 0; --new_y)
        {
            new_x = FindSelectableColumn(table, new_y, table->selected_x);

            if (new_x >= 0)
            {
                // Found a selectable widget in this column!

                ChangeSelection(table, new_x, new_y);

                return 1;
            }
        }
    }

    if (key == KEY_LEFTARROW)
    {
        int new_x;

        // Move cursor left

        for (new_x = table->selected_x - 1; new_x >= 0; --new_x)
        {
            if (SelectableCell(table, new_x, table->selected_y))
            {
                // Found a selectable widget!

                ChangeSelection(table, new_x, table->selected_y);

                return 1;
            }
        }
    }

    if (key == KEY_RIGHTARROW)
    {
        int new_x;

        // Move cursor left

        for (new_x = table->selected_x + 1; new_x < table->columns; ++new_x)
        {
            if (SelectableCell(table, new_x, table->selected_y))
            {
                // Found a selectable widget!

                ChangeSelection(table, new_x, table->selected_y);

                return 1;
            }
        }
    }

    return 0;
}
Пример #10
0
static void CalcRowColSizes(txt_table_t *table,
                            unsigned int *row_heights,
                            unsigned int *col_widths)
{
    int x, y;
    int rows;
    txt_widget_t *widget;

    rows = TableRows(table);

    memset(col_widths, 0, sizeof(int) * table->columns);

    for (y = 0; y < rows; ++y)
    {
        row_heights[y] = 0;

        for (x = 0; x < table->columns; ++x)
        {
            if (y * table->columns + x >= table->num_widgets)
                break;

            widget = table->widgets[y * table->columns + x];

            if (IsActualWidget(widget))
            {
                TXT_CalcWidgetSize(widget);
            }

            // In the first pass we ignore overflowing cells.
            if (IsOverflowingCell(table, x, y))
            {
                continue;
            }

            // NULL represents an empty spacer
            if (IsActualWidget(widget))
            {
                if (widget->h > row_heights[y])
                    row_heights[y] = widget->h;
                if (widget->w > col_widths[x])
                    col_widths[x] = widget->w;
            }
        }
    }

    // In the second pass, we go through again and process overflowing
    // widgets, to ensure that they will fit.
    for (y = 0; y < rows; ++y)
    {
        for (x = 0; x < table->columns; ++x)
        {
            unsigned int w, h;

            if (y * table->columns + x >= table->num_widgets)
                break;

            widget = table->widgets[y * table->columns + x];
            if (!IsActualWidget(widget))
            {
                continue;
            }

            // Expand column width and row heights as needed.
            CalculateWidgetDimensions(table, x, y, col_widths, row_heights,
                                      &w, &h);
            if (w < widget->w)
            {
                col_widths[x] += widget->w - w;
            }
            if (h < widget->h)
            {
                row_heights[y] += widget->h - h;
            }
        }
    }
}